How can I debug an Automator workflow?
I have a very simple automator action consisting on a shell script that should be executed in a selected folder in the finder. When I execute the action I get the message:
The action "Run Shell Script" encountered an error.
Obviously this is too generic. Is there an easy way to see a more precise error message that give me a clue of what the problem is about ?
Solution 1:
Enable the Automator Log
Automator's Log panel should display more detailed error information. You can show it by clicking the Log item in the View menu (or pressing ⌥⌘L).
Solution 2:
If you need to debug workflow outside of Automator.app, then syslog
command can be used.
Say you made Quick Action workflow with Run Shell Script action like below:
for f in "$@"
do
syslog -s -l i "Touching file: $f"
touch "$f"
done
Now you can use Quick Action in Finder:
Output of syslog
command can be viewed in Console.app:
Another way to view output of syslog
command – is to use log
command in Terminal.app.
log stream --info --debug --predicate 'process == "syslog"'
Update
We can improve Quick Action shown above by sending local notification on successful completion:
for f in "$@"
do
syslog -s -l i "Touching file: $f"
touch "$f" || exit 1 # Early exit on failure.
osascript -e "display notification \"Touched file: $f \" with title \"Automation\""
done
Solution 3:
If you're willing to use JavaScript via the Run JavaScript
action rather than shell scripting, you can get pretty great step-through debugging features that web devs nowadays are used to, i.e. the Web browser Inspect panel (in this case Safari's). Setup guide available in Apple's docs on debugging Automator JS.
Setup is simple and as of this comment is verified working on Big Sur.