I am having a similar problem. I have a file with multiple tags and I want to pass all of the tags into the AppleScript.
This is the first time I have attempted to pass attributes to an AppleScript.
I am unable to upload pictures (no longer an option?) and have no shared cloud storage where I can host screenshots. So I will attempt to describe what I have implemented in Hazel.
I have two conditions and "all" must be met:
- Tags is not blank
- Tags contain match to an attribute I have defined with the name Tags and it matches "Characters".
The action:
Run AppleScript UseTagsToFile.scpt and my Tags attribute has been added as an attributes imported into the script.
Nothing is being output at this point from the script.
Hazel's preview shows that it sees all three tags applied to my test file and it is creating a single custom attribute using the first of the three tags. I'll figure out how to get a variable number of tags later.
My AppleScript (an external file)
- Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use CTlib : script "CTsLibraries.scpt"
property WriteDebugLog : true
property taggedFileLogPath : "/Users/chip/Library/Logs/CTScriptsLogs/TaggedFileLogs.log"
property theFileAlias : alias ("/Users/chip/Downloads/Test/REPORT.pdf" as POSIX file)
property attributeList : {"#Consulting", "Searchable", ":SecState"}
set theResult to hazelProcessFile(theFileAlias, attributeList)
on hazelProcessFile(theFile, inputAttributes)
-- set logFileNameSTR to "HazelScripts.log"
set theFileString to (theFile as string)
if (WriteDebugLog) then my log_event(taggedFileLogPath, "The file path is " & (theFile as string))
set itemNumber to 0
set tags to item 1 of inputAttributes
set tags to item 1 of inputAttributes
if (WriteDebugLog) then my log_event(taggedFileLogPath, "The tags are " & tags)
--set theAttributes to inputAttributes as string
return {hazelStop:true}
When the script runs the log file contains something like the following:
2022_08_03 15:07:49-0600 The file path is Macintosh HD:Users:chip:Downloads:Test:REPORT.pdf
2022_08_03 15:07:50-0600 The tags are missing value
So for some reason the Custom Attribute is not being passed into AppleScript.
I'll keep playing with it.