Get the creation date of the selected note in Notes.app?

Been through http://www.macosxautomation.com/applescript/notes/index.html several times and the Applescript Library several times and can’t figure this out…

I’m building a larger script and need to get the creation date of the selected Notes.app note (only one).

I can refer to the notes by order: first note, tenth note, etc. and that returns a date. But if I try this…

tell application “Notes”
set theDate to creation date of the note
end tell

I get this…

Result: error “Can’t get creation date of note.” number -1728 from creation date of «class note»

I’ve tried current, selected, selection, active and no dice.

How can I refer to the selected note?

BTW - I’m running the latest El Capitan release and my notes are on an IMAP server (OS X Server)

Hi there,

Give this is try:


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

Not found a shorter way yet…

Hi,

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.

Sorry, didn’t work :frowning: : error “Can’t get text item 2 of "Notes".” number -1728 from text item 2 of “Notes”

BTW - I’m running the latest El Capitan release and my notes are on an IMAP server (OS X Server).

That x of x of x string seemed so crazy it had to work, but, no. Didn’t work :frowning: : 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).

In El Capitan it might be

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

Hi there,
It could be that you need to change the delimiter at the end of the line below to match your system."

set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Notes ” "}

On my machine this bare script does the job :

tell application "Notes"
	activate
	
	set nameOfThisNote to name of front window
	
	set creationDateOfThisNote to creation date of note nameOfThisNote
	
end tell

The events log is :

tell application "Notes"
	activate
	get name of window 1
	get creation date of note "azerty uiop"
end tell
Résultat :
date "mardi 2 octobre 2012 22:20:17"

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) mercredi 11 novembre 2015 17:36:56

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

I get "Notes ” " in the name?

Hey Yvan,

Huh. Using your script I only get “Notes” “ no note title…

Notes is in the three pane configuration “ Folders → Note-List → Note.

I only see a title if I open the note in its own window.


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

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.

-Chris

Didn’t mention, I’m on 10.9.5.

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.

That was it! :cool:

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