I'm trying to automate quickly creating new notes in the Notes.app and I would like to open my newly created note in a single floating window.
Here's my code for creating the note:
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
Any thoughts?
Notes doesn't have scripting commands for the selection per se, but the show command will select the specified note in the process of showing it. There also isn't a command to use Notes' floating window, but GUI scripting can be used to choose that menu item, for example (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
The following AppleScript opens the newly created RunTime note.
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
If you know the id of a note you can open it using the following AppleScript.
Before executing the script you need to set appropriately the values of the variables noteID and 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
Moreover you can get the id of a note using the following script. The id is copied to the clipboard.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With