Script to check number of tags

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Script to check number of tags Sat Oct 05, 2019 6:05 am • by Dave61
This is an embedded script to check how many tags a file has. As configured it specifically checks if the file has 1 tag but can easily be changed to check for other values.

Code: Select all
tell application "Finder"
   set cmd to "/usr/local/bin/Tag -l -N" & space & quote & (POSIX path of theFile) & quote
   set tagList to do shell script cmd
   set astid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to ","
   set tagCount to (count tagList's text items)
   set AppleScript's text item delimiters to astid
   if tagCount = 1 then return true
end tell

Note the shell uses "Tag", a command line tool to manage tags in macOS. You can download it here:
Posts: 109
Joined: Tue Jul 10, 2012 4:56 pm

Return to Tips & Tricks - DO NOT POST QUESTIONS