Creating a new item: note, agent, or adornment
This (in an application tell block) is the basic call to create a new root-level object, using any one of these depending on the type of item needed:
make new note
or
make new agent
or
make new adornment
Remember: without further qualifying code any new objects are always created at the root of the target document.
The default $Name string value for a note made using make new
is "new note",
for an agent it is "agent
", and for an adornment is it "adornment
".
Here, a new note is made at the root of document "Workspace.tbx" and then creates an agent (with)in that note:
set myNote to make new note in document "Workspace.tbx"
set myAgent to make new agent in myNote
or a new note as a single inline tell call:
tell front document of application "Tinderbox 10" to make new note
Setting the name for new item
(Re-)naming an item involves setting its name
property. Be aware that it is not possible to apply a note name until the note has been created, i.e. the two tasks cannot occur in the same line of code.
set myNote to make new note in document "Workspace.tbx"
set name of myNote to "inbox"
To work around this same-line usage issue, use the properties command
set myNote to make new note in document "Workspace.tbx" with properties {name:"inbox"}
When using the make new
command, note that the returned designator it gives is based on the current outline ($OutlineOrder) position of the newly created item, and subsequent calls that make or delete items might render that reference invalid. If so, use the find note in
command (see more)to re-set the variable's stored location:
set myNote to find note in it with name "inbox"
Just as with $Name other attributes can be set (see also Attribute values):
set value of attribute "Width" of myNote to 5
Creating new notes other than at root
Whilst the most trivial example inserts a new note at the root of the TBX's outline, a more likely scenario is needing to generate something new at a particular location, e.g. inside an existing container.
There is no method to create a path-type AppleScript object from a literal path string value, so a rather roundabout method is needed. This uses the find note in
method to create the location (path) object. The latter can then be used to make a new note, like so:
tell front document
set newPath to find note in it with path "/Z/Y"
set newNote to make new note at newPath
set name of newNote to "X"
end tell
The it
in line #2 above is not strictly necessary but '...find note in with...
' reads like an error in the code.
A shorter version of the above is:
tell front document
make new note at (find note in it with path "/Z/Y") with properties {name:"X"}
end tell
So the sequence is: a) find the note by path setting a variable, b) make a note using the variable as the path data, and lastly c) name the note. The latter can be skipped by using a note's properties
—as above.
See also—notes linking to here: