Apple Script Not working in Hazel

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Apple Script Not working in Hazel 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
houc@wust9bont7ZAU
 
Posts: 2
Joined: Tue Aug 24, 2021 3:24 pm

Re: Apple Script Not working in Hazel 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.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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?
houc@wust9bont7ZAU
 
Posts: 2
Joined: Tue Aug 24, 2021 3:24 pm

Re: Apple Script Not working in Hazel 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.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support