如何在Notes.App中打开特定注释

时间:2017-05-24 19:14:09

标签: 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 not work --open document {name:RunTime} end tell end tell

有什么想法吗?

4 个答案:

答案 0 :(得分:1)

注释本身没有用于selection的脚本命令,但是show命令将在显示注释时选择指定的注释。也没有使用Notes浮动窗口的命令,但是可以使用GUI脚本来选择该菜单项,例如(Mojave):

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

答案 1 :(得分:0)

  1. Notes.app AppleScript套件不支持像Safari那样在新文档中打开笔记。
  2. 标准套件包含文档,但是,您需要在告诉帐户“iCloud”内部告诉应用程序“注释 < / LI>
  3. 使用noteID时,您的最后希望可能是打开便笺位置{url}

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

答案 2 :(得分:0)

以下AppleScript将打开新创建的RunTime注释。

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

答案 3 :(得分:0)

尝试一下

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来指代笔记。上面的答案似乎不再起作用。如果有人知道,请告诉我。