Presumably this is being addressed backstage, but I would assume the AppleScript coding for attribute creation will work something like this.
set newAttribute to make new attribute with properties {name:"MyListUserAttribute", type:"list"}
Currently only name
and value
are listed as attribute properties in the AppleScript Dictionary. Presumably type
will be added as well.
Then to set the value of the new attribute one would just do the same as for existing attributes, e.g.,
set value of attribute "MyListUserAttribute" to "bee;ant;cow;ant"
The script below creates a Tinderbox test document and illustrates the current behavior with the built-in sandbox variables. Run, then click the Test Note in Outline view. AppleScript variables can be changed and the script rerun to observe the changes.
Click to expand for testing script (version 2)
# for testing AppleScript to Tinderbox
# creates test Tinderbox document
-- vary these to observe results in Tinderbox:
set theNumber to 10 -- a string "10" is ok too
set theString to "bee;ant;cow;ant"
set theAppleScriptList to {"bee", "ant", "cow", "this is this;that is that", "bee"}
set theAppleScriptDate to current date
set theAppleScriptBoolean to true
set theAppleScriptColor to {65535, 0, 0} -- or "red", "green", etc., in which case do not use RGBtoHEX()
set date1 to (current date) - (12 * hours) + (15 * minutes) + 30
set date2 to current date
set theAppleScriptInterval to date2 - date1 --> result is in seconds
set theEscapedAppleScriptList to escapeAppleScriptList(theAppleScriptList)
--> {"bee", "ant", "cow", "this is this\\;that is that", "bee"}
tell application "Tinderbox 8"
-- start new document if it does not already exist
if not (exists document "AppleScript to Attribute Tests") then
set newDoc to make new document with properties {name:"AppleScript to Attribute Tests"}
end if
-- add test note with attributes if it does not already exist
tell document "AppleScript to Attribute Tests"
if not (exists note "Test Note") then
set newNote to make new note
tell newNote
set value of attribute "Name" to "Test Note"
set value of attribute "KeyAttributes" to "MyNumber;MyList;MySet;MyString;MyDate;MyBoolean;MyColor;MyInterval"
end tell
end if
end tell
-- set the attribute values
tell front document
tell note "Test Note"
-- no conversion needed!
set value of attribute "MyString" to theString
set value of attribute "MyNumber" to theNumber
set value of attribute "MyBoolean" to theAppleScriptBoolean
-- simple conversion
set value of attribute "MyDate" to my dateToStr(theAppleScriptDate)
-- simple if no embedded ; -- otherwise need to escape first
set value of attribute "MySet" to my listToStr(theEscapedAppleScriptList)
set value of attribute "MyList" to my listToStr(theEscapedAppleScriptList)
-- if not using "red","green", etc need to convert to hex
set value of attribute "MyColor" to my RGBtoHex(theAppleScriptColor)
-- AppleScript expressed date differences in seconds; need to convert
set value of attribute "MyInterval" to my secsToHMS(theAppleScriptInterval)
end tell
activate -- to force refresh of note so new values can be viewed in key attributes
end tell
end tell
-- handlers (subroutines) to convert to strings that Tinderbox can recognize
to dateToStr(aDate) --> convert AppleScript date to string
tell aDate to return short date string & ", " & time string
end dateToStr
to listToStr(aList) -- convert AppleScript list to ;-delimited string
-- just use this if confident there are no embedded ;
-- otherwise also need to use 'escape' handler
set text item delimiters to ";"
return aList as string
end listToStr
to escapeAppleScriptList(aList) -- escape embedded ; in AppleScript list items
set escapedLst to {}
repeat with i from 1 to length of aList
tell item i of aList
if it contains ";" then
set my text item delimiters to ";"
set textItems to text items of it
set my text item delimiters to "\\;"
-- Tinderbox needs a \ to escape the ;
-- AppleScript needs an extra \ to escape the \
set theItem to textItems as string
else
set theItem to it
end if
end tell
set the end of escapedLst to theItem
end repeat
return escapedLst
end escapeAppleScriptList
to RGBtoHex(rgbTriplet)
-- https://macosxautomation.com/applescript/sbrt/sbrt-04.html
-- converts RBG triplet {0 to 65535,0 to 65535,0 to 65535} to hex
set the hexList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
set the the hexValue to ""
repeat with i from 1 to the count of the rgbTriplet
set thisValue to (item i of the rgbTriplet) div 256
if thisValue is 256 then set thisValue to 255
set x to item ((thisValue div 16) + 1) of the hexList
set y to item (((thisValue / 16 mod 1) * 16) + 1) of the hexList
set the hexValue to (the hexValue & x & y) as string
end repeat
return ("#" & the hexValue) as string
end RGBtoHex
on secsToHMS(secs)
-- Nigel Garvey https://macscripter.net/viewtopic.php?id=27203
-- needs adapting to handle more than 24 hours
tell (1000000 + secs div hours * 10000 + secs mod hours div minutes * 100 + secs mod minutes) as string to return text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7
end secsToHMS
The result after running the script should look something like this:
AppleScript strings, numbers and ānumber stringsā all come over directly. And Tinderbox directly recognizes AppleScript booleans. AppleScript dates require conversion to strings in a format that Tinderbox recognizes. AppleScript lists must first be converted to ;-delimited strings for placement in list or set attributes.
I donāt know enough about color and interval attribute types to comment.
All of this is reasonably straightforward. The main headache Iāve encountered is dealing with any ; embedded within items of AppleScript lists. The script shows one way they could be āescapedā. That works fine for MyList but results in surrounding quotes around one member in MySet (or MyList.unique) that would then need to be stripped out.