This script prepares records so that they can be found via their reference URL.
What
-
adds each selected record’s
reference URL
to the record’saliases
→ We can then use thereference URL
in a search to find the record -
creates a Smart Group in the global inbox that matches “aliases contains [reference URL]”
→ We get a Smart Group that matches exactly the selected records
Why
There are several ways this could be useful, e.g.
-
simply use resulting Smart Group
i.e. collect selected records in a Smart Group without the need to use Custom Meta Data -
drag Smart Group onto the global Smart Groups section of the sidebar
i.e. create a global Smart Group that matches exactly the selected records -
drag Smart Group onto the Smart Rules section of the sidebar
i.e. create a Smart Rule that matches exactly the selected records
Scope
As the Smart Group is created in the global inbox it may not show all selected records. To get all results you need to move it to the selected records’ database or make it a global Smart Group.
-
In case of Smart Rules and global Smart Groups the scope must be changed manually.
-
If you move the Smart Group to another database its scope updates automatically.
-- Add reference URL to aliases and create Smart Group that matches "aliases contains [reference URL]"
-- This script can be used to comfortably create a Smart Rule or global Smart Group by dragging the resulting Smart Group into the navigation sidebar.
tell application id "DNtp"
try
set theRecords to selected records
if theRecords = {} then error "Please select some records."
set theReferenceURLs to {}
repeat with thisRecord in theRecords
set thisRecord_ReferenceURL to reference URL of thisRecord
set thisRecord_Aliases to aliases of thisRecord
if thisRecord_Aliases does not contain thisRecord_ReferenceURL then
set thisRecord_Aliases_list to my tid(thisRecord_Aliases, {", ", "; ", ",", ";"})
set end of thisRecord_Aliases_list to thisRecord_ReferenceURL
set thisRecord_Aliases_string to my tid(thisRecord_Aliases_list, ", ")
set aliases of thisRecord to thisRecord_Aliases_string
end if
set end of theReferenceURLs to thisRecord_ReferenceURL
end repeat
set theSmartGroup_Query to "{any: aliases:~" & my tid(theReferenceURLs, " aliases:~") & "}"
set theOutputGroup to root of inbox
set theSmartGroup to create record with {type:smart group, search predicates:theSmartGroup_Query, search group:theOutputGroup, name:theSmartGroup_Query, exclude from search:true} in theOutputGroup
set theWindow to open window for record theOutputGroup with force
set selection of theWindow to {theSmartGroup}
activate
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
on tid(theInput, theDelimiter)
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
if class of theInput = text then
set theOutput to text items of theInput
else if class of theInput = list then
set theOutput to theInput as text
end if
set AppleScript's text item delimiters to d
return theOutput
end tid