I am newish to AppleScript but not programming. I script iTunes and use set sel to selection and then can loop through sel as a list of tracks. I was hoping to accomplish the same thing with the Notes.app.
tell application "Notes"
set selectedNotes to selection
log selectedNotes
end tell
Does anyone know how to get the current selection or at least the active note?
I’ve actually looked at both of those resources before asking my question, it does not seem that anywhere they get the current note. They add new notes/folders, iterate accounts / folders / notes but I did not see anywhere that they got the current note or the selection from Notes.app.
Quick and dirty way to get the name of the active note assuming that GUI Scripting is active.
my getMenuName("Notes", 7, -1)
--> "Notes ” avec le bonjour d'Alfred"
text ((count "Notes - ") + 1) thru -1 of result
-->"avec le bonjour d'Alfred"
--=====
(*
my selectMenu("Pages",5, 12)
==== Uses GUIscripting ====
*)
on getMenuName(theApp, mt, mi)
activate application theApp
tell application "System Events" to tell application process theApp to tell menu bar 1 to ¬
tell menu bar item mt to tell menu 1 to name of menu item mi
return result
end getMenuName
--=====
Yvan KOENIG (VALLAURIS, France) mardi 2 octobre 2012 20:50:59
Ah, OK Yvan. Once I have the name, then I can iterate through the notes looking for the right one, I guess hoping that there are not two notes named the same. Does seem like the long way around, I am wondering if there is a better way out there still?
The names are built from the first words of the note and, as far as I know, we can’t edit notes titles.
note‚n : a note in the Notes application
elements
contains attachments; contained by application, folders.
properties
name (text) : the name of the note (normally the first line of the body)
id (text, r/o) : the unique identifier of the note
container (folder, r/o) : the folder of the note
body (text) : the HTML content of the note
creation date (date, r/o) : the creation date of the note
modification date (date, r/o) : the modification date of the note
tell application "Notes"
activate
{body, id} of every note
end tell
return a list of two lists.
The first one is a list of messages body.
The second is a list ot notes ID.
The IDs are important because they are the unique way to retrieve a note.
A simple change in the contents of a note’s first line modify the list of bodies but the note’s ID is not modified.
Yvan KOENIG (VALLAURIS, France) mardi 2 octobre 2012 22:34:25