AppleScript - new note

The script you are trying to adapt is looking for a container named ‘Captain’s Log’ and within that a specific note. If it can’t find those in your document it will throw an error.

To get started you might try something simple like this. Have your document open and run this:

tell front document of application "Tinderbox 10" to make new note

That’s all there is to it! Tinderbox creates a note. But maybe not where you want it.

Let’s say you have a container at the root level named “My New Notes.” You want AppleScript to tell Tinderbox to make a new note and put it in there.

All you need to do is this:

tell front document of application "Tinderbox 10" to make new note in note "My New Notes"

Let’s say you want Tinderbox to name the note “A Brilliant Thought” at the same time that it creates it.

This will do that:

tell front document of application "Tinderbox 10" to make new note in note "My New Notes" with properties {name:"My Brilliant Thought"}

Now, suppose you want to get little fancier. You want to have AppleScript tell Tinderbox to create a new note at your specified location, give it a name, set the value of $MyString to “8888”, a lucky number for the Lunar New Year, and show MyString (and for good measure MyNumber) in DisplayedAttributes.

tell front document of application "Tinderbox 10"
	set newNote to make new note in note "My New Notes" with properties {name:"My Brilliant Thought"}
	tell newNote
		set value of attribute "MyString" to "8888"
		set value of attribute "DisplayedAttributes" to "MyString;MyNumber"
	end tell
end tell

Now let’s say you get more ambitious (or more lazy about doing things yourself). You want AppleScript to tell Tinderbox to create the note and link it to a note named “My Target Note” in the same container and label the link “agree.”

You can do that by telling AppleScript to tell Tinderbox to run Tinderbox action code, much easier than it sounds:

tell front document of application "Tinderbox 10"
	set newNote to make new note in note "My New Notes" with properties {name:"My Brilliant Thought"}
	set targetNote to note "My Target Note" in note "My New Notes"
	tell newNote
		set value of attribute "MyString" to "8888"
		set value of attribute "DisplayedAttributes" to "MyString;MyNumber"
	end tell
	my linkFromNoteToNote("agree", newNote, targetNote)
end tell

on linkFromNoteToNote(linkTypeName, fromNote, toNote)
	tell application "Tinderbox 10"
		if linkTypeName ≠ "" then
			set strType to linkTypeName
		else
			set strType to "*untitled"
		end if
		set strID to value of (attribute "ID" of toNote)
		evaluate fromNote with "linkTo(" & strID & "," & strType & ")"
	end tell
end linkFromNoteToNote

If you decide, say, to move your “My New Notes” container within a “My Notes” container (which is still at root level) you don’t have to worry about with path and the like. Unless you have deep nesting, it may be easier to use the more common AppleScript-type syntax like this:

set newNote to make new note in note "My New Notes" in note "My Notes"
6 Likes