macosapplescriptjavascript-automation

Get Id of Selected Apple Note in Applescript


I would like to get the id (or name) of the Apple Note (using the "notes" app on mac) that is currently in view (not a floated not, just the "selected" note), using either Applescript or JXA. Is that possible?

I know how to get the id of the most recently saved note with Applescript:

tell application "Notes"
  get id of note 0  //side note: I think saying "note 1" also gives same result--not sure of difference
end tell

But what about when you are looking at a note (so the note is in the foreground window), but it is not the last saved note. Is there a way to get the id of that note?


Solution

  • I've also found the following to work on macOS 11+. I got the answer based on this macscripter.net discussion, which suggests it works starting with macOS 10.15, but I am not able to verify at the moment earlier than macOS 11:

    tell application "Notes"
        set noteID to «class seld» of (selection as record)
        set noteContainerID to «class seld» of ((container of note id noteID) as record)
        set selectedNoteName to name of note id noteID
        get selectedNoteName
    end tell