Last active
December 13, 2023 17:16
-
-
Save jocap/5f5452bda5a1089f75907d52e38b97aa to your computer and use it in GitHub Desktop.
AppleScript for DEVONthink 3 that creates smart groups for all tags in the currently displayed group.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use AppleScript version "2.4" -- Yosemite (10.10) or later | |
use scripting additions | |
use framework "Foundation" | |
tell application "DEVONthink 3" | |
set theGroup to root of front window | |
set theRecordTags to tags of children of theGroup & tags of children of children of theGroup & tags of children of children of children of theGroup & tags of children of children of children of children of theGroup | |
set theDelims to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to ASCII character 0 | |
set theTags to text items of (theRecordTags as string) | |
set AppleScript's text item delimiters to theDelims | |
set theUniqueTags to (current application's NSOrderedSet's orderedSetWithArray:theTags)'s array() as list | |
set theSearchPreds to {} | |
repeat with theTag in theUniqueTags | |
if theTag as string is not "" then | |
copy "tags:" & (theTag as string) to end of theSearchPreds | |
end if | |
end repeat | |
set theSmartGroups to children of theGroup where type is smart group | |
set theExistingSearchPreds to {} | |
repeat with theSmartGroup in theSmartGroups | |
set theProps to properties of theSmartGroup | |
set theSearchPred to search predicates of theProps | |
if theSearchPreds contains theSearchPred then copy theSearchPred to end of theExistingSearchPreds | |
end repeat | |
repeat with theSearchPred in theSearchPreds | |
if theExistingSearchPreds does not contain theSearchPred then | |
set theName to ((characters 6 thru (count theSearchPred) of theSearchPred) as string) | |
set theName to ((current application's NSString's stringWithString:theName)'s capitalizedStringWithLocale:((current application's NSLocale's currentLocale()))) as text | |
create record with {type:smart group, name:theName, search predicates:theSearchPred, search group:theGroup} in theGroup | |
end if | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment