为导入到 iCloud 的笔记设置正确的日期
Setting the correct date on notes imported to iCloud
我正在使用以下脚本(我在网上找到的)通过 Notes OS X 应用程序将旧笔记导入 iCloud。导入工作正常,但所有导入的笔记显示为导入时创建的。
我写了一段代码,应该从原始笔记文件复制日期并将新笔记的日期设置为该日期,但由于某种原因它不起作用。日期被正确复制,据我所知,第二部分也执行了,因为没有任何错误,但日期总是以导入日期结束。
如果有人能发现问题或有任何想法,我将不胜感激!
-- choose the folder with the notes
set notesFolder to choose folder
-- find all the files in that folder
tell application "Finder"
set noteFiles to (files of entire contents of notesFolder) as alias list
end tell
-- get the name of the account that you want to add the notes to
set accountName to getNameOfTargetAccount()
-- get the name of the folder to add the notes to
set folderName to getNameOfTargetFolderOfAccount(accountName)
-- make sure the folder exists in Notes
tell application "Notes"
tell account accountName
if not (exists folder folderName) then make new folder with properties {name:folderName}
end tell
end tell
repeat with noteFile in noteFiles
-- get the note name from the file name and the corresponding dates
set {noteName, ext} to getName_andExtension(noteFile)
tell application "Finder"
set noteModified to modification date of noteFile
set noteCreated to creation date of noteFile
end tell
-- get the file's text as html
if ext is "html" then
set noteText to read noteFile
else
-- convert the file's contents into html code
set noteText to do shell script "/usr/bin/textutil -stdout -convert html " & quoted form of POSIX path of noteFile & " | /usr/bin/tidy -ib -utf8"
end if
-- add the note to the folder
tell application "Notes"
tell account accountName
tell folder folderName
make new note with properties {name:noteName, body:noteText, modification date:noteModified, creation date:noteCreated}
end tell
end tell
end tell
end repeat
(****************** SUBROUTINES *****************)
-- this lets you choose which acount you want to target
-- if there's only 1 account then that account name is returned
on getNameOfTargetAccount()
tell application "Notes"
if (count of accounts) is greater than 1 then
set theseAccountNames to the name of every account
set thisAccountName to choose from list theseAccountNames with prompt "Add note to which account?"
if thisAccountName is false then error number -128
set thisAccountName to thisAccountName as text
else
set thisAccountName to the name of first account
end if
return thisAccountName
end tell
end getNameOfTargetAccount
-- this lets you choose which folder you want to target from an account
-- if there's only 1 folder then that folder name is returned
on getNameOfTargetFolderOfAccount(accountName)
set folderName to missing value
tell application "Notes"
tell account accountName
if (count of folders) is greater than 1 then
set theseFolderNames to the name of every folder
set folderName to choose from list theseFolderNames with prompt "Add note to which folder?"
if folderName is false then error number -128
set folderName to folderName as text
else
set folderName to the name of first folder
end if
end tell
end tell
return folderName
end getNameOfTargetFolderOfAccount
on getName_andExtension(f)
set f to f as text
set {name:nm, name extension:ex} to info for file f without size
if ex is missing value then
set ex to ""
else
set nm to text 1 thru ((count nm) - (count ex) - 1) of nm
end if
return {nm, ex}
end getName_andExtension
在 Notes.app
的脚本字典中,它指出那些是只读的 (r/o
):
creation date (date, r/o) : the creation date of the note
modification date (date, r/o) : the modification date of the note
我正在使用以下脚本(我在网上找到的)通过 Notes OS X 应用程序将旧笔记导入 iCloud。导入工作正常,但所有导入的笔记显示为导入时创建的。
我写了一段代码,应该从原始笔记文件复制日期并将新笔记的日期设置为该日期,但由于某种原因它不起作用。日期被正确复制,据我所知,第二部分也执行了,因为没有任何错误,但日期总是以导入日期结束。
如果有人能发现问题或有任何想法,我将不胜感激!
-- choose the folder with the notes
set notesFolder to choose folder
-- find all the files in that folder
tell application "Finder"
set noteFiles to (files of entire contents of notesFolder) as alias list
end tell
-- get the name of the account that you want to add the notes to
set accountName to getNameOfTargetAccount()
-- get the name of the folder to add the notes to
set folderName to getNameOfTargetFolderOfAccount(accountName)
-- make sure the folder exists in Notes
tell application "Notes"
tell account accountName
if not (exists folder folderName) then make new folder with properties {name:folderName}
end tell
end tell
repeat with noteFile in noteFiles
-- get the note name from the file name and the corresponding dates
set {noteName, ext} to getName_andExtension(noteFile)
tell application "Finder"
set noteModified to modification date of noteFile
set noteCreated to creation date of noteFile
end tell
-- get the file's text as html
if ext is "html" then
set noteText to read noteFile
else
-- convert the file's contents into html code
set noteText to do shell script "/usr/bin/textutil -stdout -convert html " & quoted form of POSIX path of noteFile & " | /usr/bin/tidy -ib -utf8"
end if
-- add the note to the folder
tell application "Notes"
tell account accountName
tell folder folderName
make new note with properties {name:noteName, body:noteText, modification date:noteModified, creation date:noteCreated}
end tell
end tell
end tell
end repeat
(****************** SUBROUTINES *****************)
-- this lets you choose which acount you want to target
-- if there's only 1 account then that account name is returned
on getNameOfTargetAccount()
tell application "Notes"
if (count of accounts) is greater than 1 then
set theseAccountNames to the name of every account
set thisAccountName to choose from list theseAccountNames with prompt "Add note to which account?"
if thisAccountName is false then error number -128
set thisAccountName to thisAccountName as text
else
set thisAccountName to the name of first account
end if
return thisAccountName
end tell
end getNameOfTargetAccount
-- this lets you choose which folder you want to target from an account
-- if there's only 1 folder then that folder name is returned
on getNameOfTargetFolderOfAccount(accountName)
set folderName to missing value
tell application "Notes"
tell account accountName
if (count of folders) is greater than 1 then
set theseFolderNames to the name of every folder
set folderName to choose from list theseFolderNames with prompt "Add note to which folder?"
if folderName is false then error number -128
set folderName to folderName as text
else
set folderName to the name of first folder
end if
end tell
end tell
return folderName
end getNameOfTargetFolderOfAccount
on getName_andExtension(f)
set f to f as text
set {name:nm, name extension:ex} to info for file f without size
if ex is missing value then
set ex to ""
else
set nm to text 1 thru ((count nm) - (count ex) - 1) of nm
end if
return {nm, ex}
end getName_andExtension
在 Notes.app
的脚本字典中,它指出那些是只读的 (r/o
):
creation date (date, r/o) : the creation date of the note
modification date (date, r/o) : the modification date of the note