Macos AppleScript:如何在Apple Notes中自动创建新便笺

Macos AppleScript:如何在Apple Notes中自动创建新便笺,macos,applescript,Macos,Applescript,我正在尝试在notes.app中自动快速创建新便笺,我希望在单个浮动窗口中打开新创建的便笺 以下是我创建便笺的代码: set RunTime to ((current date)) as string tell application "Notes" activate tell account "iCloud" make new note at folder "Notes" with properties {name:RunTime} --does

我正在尝试在
notes.app
中自动快速创建新便笺,我希望在单个浮动窗口中打开新创建的便笺

以下是我创建便笺的代码:

set RunTime to ((current date)) as string
tell application "Notes"
    activate
    tell account "iCloud"
        make new note at folder "Notes" with properties {name:RunTime}
        --does not work
        --open document {name:RunTime}
    end tell
end tell
有什么想法吗

  • Notes.app AppleScript suite不支持新文档中的开头注释,例如Safari
  • 标准套件包含文档,但是,您需要在tell帐户“iCloud”内部tell应用程序“Notes”之外使用它
  • 您最后的希望可能是在使用noteID时打开note位置{url}

    set noteID to make new note at folder "Notes" with properties {name:RunTime}
    

  • 以下AppleScript打开新创建的运行时注释

    tell application "Notes"
        tell account "iCloud"
            make new note at folder "Notes" with properties {name:"RunTime", body:"RunTime body"}
            set noteRunTime to get notes whose name is "RunTime"
            show item 1 of noteRunTime
        end tell
    end tell
    
    如果您知道便笺的id,可以使用以下AppleScript打开它

    在执行脚本之前,需要适当地设置变量noteID和myAccount的值

    set noteID to "x-coredata://05A6F727-5F0B-478F-A493-B2DFAEA12067/ICNote/p153"
    set myAccount to "iCloud"
    
    tell application "Notes"
        tell account myAccount
            set aNote to get notes whose id is noteID
            if aNote is {} then display dialog "The note was not found."
            show item 1 of aNote        
        end tell
    end tell
    
    此外,您可以使用以下脚本获取便笺的id。id将复制到剪贴板

    tell application "Notes"
        activate
        set noteNames to name of notes
        set chosenNote to (choose from list noteNames)
        if (chosenNote is false) then error number -128 -- Cancel button.
        set aNote to get notes whose name is item 1 of chosenNote
        set noteID to id of item 1 of aNote
        set the clipboard to noteID
        display dialog "The id of the selected note is " & noteID
    end tell
    
    试试这个

    tell application "Notes"
        tell account "iCloud"
            tell folder "Notes" -- you can remove this to show notes from any folder
                show note 1 -- notes are indexed by their last edited date
            end tell
        end tell
    end tell
    

    不幸的是,我还没有弄清楚如何根据笔记的名称或id引用笔记。上面的答案似乎不再有效。如果有人知道如何引用笔记,请告诉我。

    notes本身没有用于
    选择的脚本命令,但是
    show
    命令将在过程中选择指定的笔记也没有使用Notes浮动窗口的命令,但可以使用GUI脚本选择该菜单项,例如(Mojave):


    你说的不是名为“名称”的显示便笺“
    或名为“id”的显示便笺id“?我现在已经知道如何按便笺的名称引用便笺。但是,我不知道如何按便笺id引用便笺。@red\u meaneyou可以通过查找(名称、索引等)来获取id或者在创建时获取它,然后使用
    note id“id“
    。我已经试过了,但还是没能成功。我想一定有虫子。你能看看你是否能用一个简单的脚本来显示一个带有特定id的便条吗?这似乎不再是一个答案了。我已经为原始海报的问题添加了一个答案(尽管他们已经有一段时间没有出现了),这可能会有所帮助。
    set example to (current date) as string
    tell application "Notes"
        activate
        tell folder "Notes" -- or whatever
            set theNote to make new note with properties {name:example} -- 'make' returns a reference to the new note
        end tell
    
        try
            (* If not making a new note, existing notes can be referenced by using id or name properties:
                    set theNote to note id "xyz" -- id property
                    -- or --
                    set theNote to note example -- name property
                    -- or --
                    tell (get every note whose name is example) -- filter form
                        if it is {} then error "A note named \"" & example & "\" was not found."
                        set theNote to its first item
                    end tell
            *)
            show theNote -- also selects the note
            delay 0.25
            tell application "System Events" to click menu item "Float Selected Note" of menu "Window" of menu bar item "Window" of menu bar 1 of application process "Notes"
        on error errmess -- not able to get the note
            log errmess
            display alert "Error getting note" message errmess
        end try
    end tell