1. Watch Downloads folder for new PDF files
2. If contents match 3 different options then
3. Run AppleScript to rename the file.
4. Move the file to another folder.
Steps 1 and 2 work correctly. The log matches the file based on kind and three content strings.
Step 3 AppleScript renames files with names like December 27, 2018.pdf to 2018-12-27.pdf
According to the log, the Hazel step 3 fails with OSAScriptErrorNumberKey = "-1708".
The AppleScript has the following handler:
- Code: Select all
on hazelMatchFile(theFile, inputAttributes)
-- Add your logic here. Don't need the inputAttributes.
my CheckName(theFile)
-- ‘theFile’ is an alias to the file that matched.
-- ‘inputAttributes’ is an AppleScript list of the values of any attributes you told Hazel to pass in.
-- Be sure to return true or false (or optionally a record) to indicate whether the file passes this script.
return true
end hazelMatchFile
The CheckName handler does the work of renaming the file. I've tested the handler manually using:
- Code: Select all
(*
tell application "Finder"
set thisFile to alias "Macintosh HD:Users:myUserName:Downloads:December 27, 2018.pdf"
--my CheckName(thisFile)
my hazelMatchFile(thisFile, "")
end tell
*)
Both options above work correctly when manually running the script through Script Debugger.
If anyone has ideas about what to try next, I'd appreciate it!