How do you write and debug scripts, like the one above, while working in DT?
Apple’s Script Editor.
I’ve used it for 20+ years.
I generally start with a non-smart rule script in Script Editor, then modify it for smart rule (or other) uses, if needed. In most circumstances, this is usually just a modification of changing the theRecords variable.
For your testing, here is the code…
set od to AppleScript's text item delimiters
tell application id "DNtp"
set theRecords to (selected records) -- THIS IS WHERE THE VARIABLE IS SET IN THIS STANDALONE VERSION. REMOVE OR COMMENT OUT THIS LINE FOR USE IN THE SMART RULE**strong text**
set AppleScript's text item delimiters to "="
set tagList to {}
repeat with thisRecord in theRecords
set theTags to (tags of thisRecord)
repeat with theTag in theTags
set attribs to (text items of theTag)
if (count attribs) = 2 then
add custom meta data (item 2 of attribs) for (item 1 of attribs) to thisRecord
else
copy theTag to end of tagList
end if
end repeat
set tags of thisRecord to tagList
end repeat
set AppleScript's text item delimiters to od
end tell
See how it’s almost identical to the smart rule version?