Working on a smart rule to group DEVONagent results into a group by date and struggling with the AppleScript. It correctly creates the group in the inbox, but then doesn’t process any of the matched records:
on performSmartRule(theRecords)
set {year:y, month:m, day:d} to (current date)
set thisMonth to texts -1 thru -2 of ("0" & (m as number))
set thisDay to texts -1 thru -2 of ("0" & d)
set customDate to ("" & y & "-" & thisMonth & "-" & thisDay)
set groupName to "DEVONagent Saved Search " & customDate
set groupPath to "/" & groupName as text
tell application id "DNtp"
set theGroup to create record with {name:groupName, type:group, label:1, tags:"DEVONagent, Saved Searches"} in inbox
set groupLocation to (groupPath in inbox)
repeat with theRecord in theRecords
move record theRecord to groupLocation
end repeat
end tell
end performSmartRule
For reference, here is the rest of the smart rule:
Interesting–yes it compiles and creates the group with the correct name using texts however I did make that change.
But even with that change, still does not move the matched items to the newly created group–the error I’m getting in the log is “on performSmartRule (can’t make groupPath of inbox into type reference.)”
(And on a related note, it was a pain to copy that error from the log to this message since the log window disappears when DT doesn’t have focus).
You need to use root of inbox. Not sure whether you want one tag DEVONagent, Saved Searches or DEVONagent and Saved Searches, however tags is of type list. Add quotes if you want two separate tags.
Take a look at Script Debugger, it’s dictionary window makes it easy to check what type is needed etc. There’s a free version.
on performSmartRule(theRecords)
tell application id "DNtp"
try
set {year:y, month:m, day:d} to (current date)
set thisMonth to items -1 thru -2 of ("0" & (m as number))
set thisDay to items -1 thru -2 of ("0" & d)
set customDate to ("" & y & "-" & thisMonth & "-" & thisDay)
set groupName to "DEVONagent Saved Search " & customDate
set groupPath to "/" & groupName as text
set theGroup to create record with {name:groupName, type:group, label:1, tags:{"DEVONagent, Saved Searches"}} in root of inbox
repeat with theRecord in theRecords
move record theRecord to theGroup
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
end performSmartRule