Apple Script Not working in Hazel

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
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