Page 1 of 1

Apple Script Not working in Hazel

PostPosted: Tue Aug 24, 2021 3:28 pm
by houc@wust9bont7ZAU
I have the following Apple Script. It works fine when run in Automator and also directly from the Apple Script editor however it does not work when run from Hazel. I tried both as and embedded Apple Script and as pointing to a saved Apple Script file.

the script is:
set oldDelims to AppleScript's text item delimiters
set the_strings_to_strip to {" *OCR", " Medical 2021"} --List what is to be stripped of end of name include any preceeding spaces

tell application "Finder"
set the_files to the selection
--
repeat with a_file in the_files
set the_name to name of a_file
repeat with I from 1 to count of the_strings_to_strip
set AppleScript's text item delimiters to item I of the_strings_to_strip
set the_text_items to text items of the_name
set AppleScript's text item delimiters to ""
set the_name to the_text_items as string
end repeat
set the name of a_file to the_name
end repeat
--
set AppleScript's text item delimiters to oldDelims
end tell

Re: Apple Script Not working in Hazel

PostPosted: Wed Aug 25, 2021 10:34 am
by Mr_Noodle
When using it as an embedded script, what kind of problem are you seeing? Also, it looks like it's getting the files from the selection in Finder, which is probably not what you want here. You should be using the argument passed in.

Re: Apple Script Not working in Hazel

PostPosted: Thu Aug 26, 2021 12:21 pm
by houc@wust9bont7ZAU
Mr_Noodle wrote:When using it as an embedded script, what kind of problem are you seeing? Also, it looks like it's getting the files from the selection in Finder, which is probably not what you want here. You should be using the argument passed in.

That appears to be my exact problem. Any suggestions on how to use the arguments passed in?

Re: Apple Script Not working in Hazel

PostPosted: Fri Aug 27, 2021 10:20 am
by Mr_Noodle
There are instructions in the AppleScript editor as well as in the manual. You should be using the "theFile" variable.