tell application "Notes"
activate
set nameOfThisNote to name of front window
set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Notes ” "}
set nameOfThisNote to text item 2 of nameOfThisNote
set AppleScript's text item delimiters to atid
set creationDateOfThisNote to creation date of note nameOfThisNote
end tell
Notes.app doesn’t have a selection property.
A workaround is to get the selected row via GUI scripting.
tell application "System Events"
tell process "Notes"
set selectedRow to 1st row of table 1 of scroll area 1 of group 1 of splitter group 1 of window 1 whose selected is true
set rowName to name of UI element 1 of selectedRow
end tell
end tell
tell application "Notes"
set selectedNote to note rowName
set theDate to creation date of selectedNote
end tell
The script has been written and tested on OS X 10.10 Yosemite. UI elements could change across system versions.
That x of x of x string seemed so crazy it had to work, but, no. Didn’t work : error “System Events got an error: Can’t get group 1 of splitter group 1 of window 1 of process "Notes". Invalid index.” number -1719 from group 1 of splitter group 1 of window 1 of process “Notes”
BTW - I’m running the latest El Capitan release and my notes are on an IMAP server (OS X Server).
set selectedRow to 1st row of table 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of window 1 whose selected is true
tell application "Notes"
activate
set nameOfThisNote to name of front window
set creationDateOfThisNote to creation date of note nameOfThisNote
end tell
For some reason I have to insert the code below for that to work?
set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Notes ” "}
set nameOfThisNote to text item 2 of nameOfThisNote
set AppleScript's text item delimiters to atid
In order to get this working on OSX 10.11.1 I’ve got to jump through some hoops…
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/11/11 12:45
# dMod: 2015/11/11 13:07
# Appl: Notes.app & System Events
# Task: Acquire selected note for processing.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Notes, @System_Events, @Acquire, @Selected, @Note
-------------------------------------------------------------------------------------------
tell application "System Events"
tell application process "Notes"
tell (first window whose subrole is "AXStandardWindow")
tell table 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1
set selectedNotes to rows whose selected is true
set theRow to item 1 of selectedNotes
set noteTitle to value of static text 1 of UI element 1 of theRow
set noteModDate to value of static text 3 of UI element 1 of theRow
end tell
end tell
end tell
end tell
tell application "Notes"
set noteList to notes whose name is noteTitle
if length of noteList = 1 then
set theNote to item 1 of noteList
else if length of noteList > 1 then
repeat with i in noteList
tell (get modification date of i) to set modDateStr to its short date string & " " & its time string
if modDateStr contains noteModDate then
set theNote to contents of i
end if
end repeat
end if
set noteProps to properties of theNote
end tell
-------------------------------------------------------------------------------------------
The current Notes app is a study in poor program design. Poor UI. Poor AppleScript support.
This does work for me, but only if I have double-clicked the note so that it is in its own window. This isn’t how I typically use notes and I apologize for not making this clear, earlier. I view and create notes in the two pane view: list|note (sometimes in the three pane view: accounts|list|note). I almost never open a note in it’s own window.
Here is the full script that works for me on the latest El Capitan release, viewing notes in the notes app in a list|note setup:
tell application "System Events"
tell process "Notes"
set selectedRow to 1st row of table 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of window 1 whose selected is true
set rowName to name of UI element 1 of selectedRow
end tell
end tell
tell application "Notes"
set selectedNote to note rowName
set theDate to creation date of selectedNote
end tell