IMPORTANT: case sensitivity when resolving note name matches differs from action code
AppleScript's named
operator is, unfortunately, case-insensitive. Though consistent with Finder it is unlike normal Tinderbox treatment of $Name data. So, be aware that:
note "X"
is only a short way to write:
note named "X"
… i.e. both examples use named
, even if it is only explicit in the latter. This means the code acts case-insensitively to match the first ($OutlineOrder-based) match to notes named 'X' or 'x' which otherwise would be unique names in Tinderbox (action code). By contrast Tinderbox action code can distinguish note 'X' from note 'x' but if passed two notes called 'x' as a match, it would pick the first by outline order.
If affected by this consider resolving correct identity based on $Path or $IDString data instead and see the find note in
example further below under referencing notes. If needing to do multiple operations on a note (or in scope of a note) use a more precise method to set a reference to the note and then re-use the reference as needed.
Creating new notes
This creates a new top-level note, and creates an agent in that note:
set myNote to make new note in document "Workspace.tbx"
set myAgent to make new agent in myNote
When using the make new command, note that the returned designator it gives is based on the current outline position of the newly created note, and subsequent calls that make or delete notes might render it invalid.
To set the $Name of the note [sic] created in the code above:
set name of myNote to "inbox"
Then set its $Width (see also Attribute values):
set value of attribute "Width" of myNote to 5
Getting references to notes
To get a list of all the note inside the referenced 'myNote':
get notes in myNote
Or, the agents in 'myNote':
get agents in myNote
Or, the adornments in 'myNote':
get adornments in myNote
To return the name of the third top-level note in the specified document:
name of note 3 of document "Workspace.tbx"
To return a reference to the designated note:
find note in [note or document] with path "/path/to/note"
If the target is a document, the path should be an absolute path. If the target is a note, the path can be an absolute path or a relative path with respect to that note.
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
… see more on selections.
To return a reference to myNote's container, i.e. its 'parent' property (see Note properties below),:
set theContainer to find note in myNote with path "parent"
Moving a note
To move a note to the specified container (as specified in the example above):
move note named "X" to theContainer
Deleting a note
Use:
delete myNote
Note Properties
Each note object has a number of AppleScript properties:
-
child
(action code designator 'child' or 'child[0]') -
color
(i.e. $Color) -
lastChild
(action code designator 'lastChild') -
name
(i.e. $Name) -
nextSibling
(action code designator 'nextSibling') -
parent
(action code designator parent) -
previousSibling
(action code designator 'prevSibling') -
text
(i.e. $Text)
In a few cases the property is an alternate way to access a specific system attribute for the note, but for most these properties are the equivalent of calculated item designators in action code.