在导入 iCloud 的笔记上设置正确的日期

Posted

技术标签:

【中文标题】在导入 iCloud 的笔记上设置正确的日期【英文标题】:Setting the correct date on notes imported to iCloud 【发布时间】:2015-03-22 20:58:02 【问题描述】:

我正在使用以下脚本(我在网上找到)通过 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

【问题讨论】:

【参考方案1】:

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

【讨论】:

顺便说一句:笔记存储在 sqlite 数据库中(~/Library/Containers/com.apple.Notes/Data/Library/Notes/NotesV3.storedata) 感谢您的信息。我希望,因为我试图在创建笔记的过程中设置它们,所以它会通过。我最终在外部驱动器的分区上安装了 10.7 Lion,并使用 iTunes/Mail 组合来导入日期完整的笔记。

以上是关于在导入 iCloud 的笔记上设置正确的日期的主要内容,如果未能解决你的问题,请参考以下文章

苹果通讯录都导不出来

如何正确重置应用程序的 iCloud 存储

苹果手机怎么不能导入通讯录呢

在SAS中导入CSV数据时如何设置正确的日期格式?

iCloud 文档选择器:应用文件夹在导入时被禁用

vs2008中想使用M97日期控件,怎么导入和设置?