Selections are an element of the document
object.
Setting a selection
To select a named note:
set selected note of front document to "Test note"
… selects a note. N.B. presently, selecting more than one note is not supported.
Working with selections
The current selection:
set mySelection to selection of front document
… returns a list of a selected note(s). If several notes are selected, to code returns one of those notes, typically the first selected note. If no notes are selected, this returns 'missing value'.
To ensure all of the currently selected note(s) are captured:
set mySelection to every selection of front document
Note that selection
is an element of a document
object, so must be used with a specified document as above, or the code will not compile. But that form cannot be used if already inside a document tell block (code errors). Instead use selected note
as shown below, to get a reference to a selected note:
set mySelection to selected note of front document
… returns the selected note. If already inside a document tell use :
set mySelection to selected note
If several notes are selected, the selection
code returns one of those notes, typically the first selected note. If no notes are selected, this returns 'missing value'.
To put a list of $Name (or other attributes) of all selected notes into an AppleScript list called 'theNames':
tell selection of front document to set the theNames to value of attribute "Name"
selected note
or item(s) of selection
offer the same properties as for a note object.
Acting on each item in a selection of notes
A way to act on all selected notes (a common operation):
repeat with anItem in selection of front document
set value of attribute "Color" of anItem to "red"
end repeat