That is helpful. Thanks!
I would replace the named
in all the examples with the simpler, more common syntax. (I see that was changed in a few of the examples).
I canât get set selection to myNote
to work here. Maybe Iâm doing it wrong.
Possible useful generic examples for scripters:
To put a list of names (also works for other attributes) of all selected notes into an AppleScript list (theNames):
tell selection of front document to set the theNames to value of attribute "Name"
One 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
Not for basic documentation, of course, but hereâs a script that illustrates a few of the many things that can be done: run Tinderbox action code for trig functions that AppleScript doesnât have to position notes on the canvas in a circle, create links using act on
, etc.
Click triangle to see script
-- have a Tinderbox document open, then run; create a "Circular" container at root
property containerName : "Circular" -- name of empty container at root level
property noteSpace : 8 -- spacing between notes on circle -- vary as wanted
property offsetOnPerim : 140 -- vary to adjust position of starting note in circle perimiter
property noteWidth : 4.25 -- width of each note on circle
property linkLabel : "" -- label of links (if any)
set perimNoteNames to {"the mentally unfit don't have to fly", "but don't claim you're unfit!", "combat missions are dangerous", "and fear is a rational response to danger", "so the fearful and traumatized are not unfit"}
set centerNoteName to "Unfitness is fitness!"
-- alternative demo - uncomment following two lines to see
-- set perimNoteNames to {"Tinderbox is a toolbox", "toolboxes have many tools", "many tools require more skills", "more skills require training", "training limits flexibility"}
-- set centerNoteName to "many tools lead to rigidity!"
set noteCount to length of perimNoteNames -- number of notes to place in circle
-- calculate length of perimeter needed for that spacing, number of seats
set cPerim to noteCount * noteSpace
-- derive the radius from perimiter
set cRadius to cPerim / (2 * pi)
-- set the origin (intersection of x & y axes on Tinderbox map)
set {xOrigin, yOrigin} to {0, 0}
-- make center of circle 1 radius to the right and 1 radius down (TB y-axis is inverted; positive is down)
set {xCircleCenter, yCircleCenter} to {xOrigin + cRadius, yOrigin + cRadius}
set noteRecords to {} -- an associative list to hold information that will be used to create notes
repeat with i from 1 to noteCount
-- calculate the angle for that note
set cAngle to (i * (360 / noteCount))
--adjust position of first note on the perimeter
set cAngle to cAngle + offsetOnPerim
-- convert degrees to radians
set cRadians to cAngle * (2 * pi) / 360
-- calculate offsets from center of circle with basic trigonometry formulas
set hOffset to cRadius * (my cos:cRadians) -- cosine is adjacent/hypoteneuse
set vOffset to cRadius * (my sin:cRadians) -- sine is opposite/hypoteneuse
-- apply offsets to derive map coordinates
set {xPosition, yPosition} to {xCircleCenter + hOffset, yCircleCenter + vOffset}
-- give note a dummy name in sequence
set noteName to item i of perimNoteNames
-- place name and coordinates into AppleScript record and add record to the associative list
set end of noteRecords to {thename:noteName, x:xPosition, y:yPosition}
end repeat
-- noteRecords -->{{thename:"Note 1", x:10, y:10}, {thename:"Note 2", x:6.4, y:12.7}...}
tell front document of application "Tinderbox 9"
-- create the container if it doesn't already exist
if not (exists note containerName) then make new note with properties {name:containerName}
-- stop script if the container already contains notes
if notes of note containerName is not {} then error "Make sure container is empty and run again"
-- loop through the associative list and tell TB to create a note for each record there
repeat with aRecord in noteRecords
-- make new note in specified container at coordinates in that record
set newNote to (my makeNewNote:(thename of aRecord) inContainer:containerName xCoord:(x of aRecord) yCoord:(y of aRecord))
-- add any desired customization to the note
tell newNote
set value of attribute "MapTextSize" to 90
set value of attribute "Width" to noteWidth
set value of attribute "NameAlignment" to "center"
end tell
-- use Tinderbox action code to link new note to its previous sibling - TB just ignores if no previous sibling
act on newNote with "linkFrom(prevSibling," & linkLabel & ")"
end repeat
-- complete the circularity by linking last note to first note
act on newNote with "linkTo(firstSibling," & linkLabel & ")"
-- add a note in center of circle (if wanted) with large font
set centerNote to my makeNewNote:centerNoteName inContainer:containerName xCoord:xCircleCenter yCoord:yCircleCenter
tell centerNote
set value of attribute "MapTextSize" to 110
set value of attribute "Width" to 5
set value of attribute "NameAlignment" to "center"
set value of attribute "Shape" to "oval"
end tell
end tell
-------------------------- handlers / subroutines ---------------------------------
-- handler to make a new note at a specified location in front Tinderbox document
on makeNewNote:thename inContainer:containerName xCoord:xPosition yCoord:yPosition
tell front document of application "Tinderbox 9"
set newNote to make new note at note containerName with properties {name:thename}
set value of attribute "Xpos" of newNote to xPosition
set value of attribute "Ypos" of newNote to yPosition
return newNote
end tell
end makeNewNote:inContainer:xCoord:yCoord:
-- AppleScript doesn't have native sin and cos functions -- so just borrow them from Tinderbox!
on sin:cRadians
tell front document of application "Tinderbox 9" to evaluate it with "sin(" & cRadians & ")"
end sin:
on cos:cRadians
tell front document of application "Tinderbox 9" to evaluate it with "cos(" & cRadians & ")"
end cos:
Iâve forgotten how I figured out all that trig. But aside from its demo value this is good at creating circular arguments! ⊠Or Catch 22.