AppleScript returns different results manually vs hazel

Hello,
I have a simple AppleScript that I am having trouble getting Hazel to match.
If I use the commented out line to manually set the path to a file and comment out the handler information the script runs as expected and returns the desired results in the code below. However, when I create a hazel rule that "Passes AppleScript" and point the rule to the AppleScript below it does not match. The rule will match if I swap the position of true and false but it then moves the wrong files to the desired location. It should be something simple with the syntax but I can't get it to work as expected. I have read through "Using AppleScript or JavaScript" but am still missing something.
Now, this simple rule should really be accomplished through Hazel's UI. However, my goal is to really fine tune a folder structure consisting of thousands of files and multiple levels. I would like to be able to use the same criteria throughout multiple rules at different levels for different reasons and by able to dynamically update the "matching string" criteria dynamically. That way I don't have to manually update multiple rules with the same information.
Ideally in my mind any "names contains" rules could be compared against a text file or two containing a list of strings. The appropriate "Passes AppleScript" rules would be set up either internally or externally and pointed to the correct text file so all I have to do is update ether text document.
Is there an easier way?
I have a simple AppleScript that I am having trouble getting Hazel to match.
If I use the commented out line to manually set the path to a file and comment out the handler information the script runs as expected and returns the desired results in the code below. However, when I create a hazel rule that "Passes AppleScript" and point the rule to the AppleScript below it does not match. The rule will match if I swap the position of true and false but it then moves the wrong files to the desired location. It should be something simple with the syntax but I can't get it to work as expected. I have read through "Using AppleScript or JavaScript" but am still missing something.
Now, this simple rule should really be accomplished through Hazel's UI. However, my goal is to really fine tune a folder structure consisting of thousands of files and multiple levels. I would like to be able to use the same criteria throughout multiple rules at different levels for different reasons and by able to dynamically update the "matching string" criteria dynamically. That way I don't have to manually update multiple rules with the same information.
Ideally in my mind any "names contains" rules could be compared against a text file or two containing a list of strings. The appropriate "Passes AppleScript" rules would be set up either internally or externally and pointed to the correct text file so all I have to do is update ether text document.
Is there an easier way?
- Code: Select all
on hazelMatchFile(theFile, inputAttributes)
--set pathList to quoted form of POSIX path of (choose file with prompt "Please choose a file:" default location (path to desktop))
set criteria to {"Bob", "Susan"}
repeat with i from 1 to (count criteria)
if theFile contains item i of criteria then
return true
exit repeat
else
return false
end if
end repeat
end hazelMatchFile