Shell script failing in Automator but works if I copy/paste into Terminal

automatorcommand linescriptterminal

Workflow I'm trying to achieve:

  1. Export SVG file from Adobe Illustrator to Desktop
  2. Drag SVG file from Desktop onto Automator Droplet
  3. Automator runs script (basic summary below)
  4. Script executes and leaves me with on ICO

My script is:

ROOT=~/Desktop/
TRASH=~/.Trash/
INK=/Applications/Inkscape.app/Contents/Resources/bin/inkscape

$INK --export-png $ROOTtest_256.png -w 256 -h 256 $1
$INK --export-png $ROOTtest_128.png -w 128 -h 128 $1
$INK --export-png $ROOTtest_064.png -w 064 -h 064 $1
$INK --export-png $ROOTtest_048.png -w 048 -h 048 $1
$INK --export-png $ROOTtest_040.png -w 040 -h 040 $1
$INK --export-png $ROOTtest_032.png -w 032 -h 032 $1
$INK --export-png $ROOTtest_024.png -w 024 -h 024 $1
$INK --export-png $ROOTtest_016.png -w 016 -h 016 $1
convert $ROOTtest_*.png $ROOTTEST.ico
cp $ROOTtest_*.png $1 $TRASH

Summary of script:

  1. Take SVG (from drag & drop) and export multiple PNGs at specified sizes
  2. Take multiple PNGs and merge into one ICO
  3. Send original SVG and PNGs to Trash

Errors / Problems:

  • When I test run the script in Automator I get this error: -: line 12: convert: command not found. However, I can paste convert ~/Desktop/test_*.png ~/Desktop/Test.ico into Terminal and everything will work fine. Any idea why Automator can't seem to find this command?
  • Even though line 12 may not be working properly I would still expect all the lines above it to work however I see no signs of them working. Upon dropping an SVG onto the Automator Droplet I would expect to see 8 PNGs on my Desktop but nothing appears. Even after deleting the last line that moves the PNGs and original SVG to the trash, nothing appears on my desktop.

Any help will be GREATLY appreciated!

Best Answer

You have probably customized the command search path environment variable PATH to locate convert because it isn't installed in a standard OS X location.

When the Automator shell-script action runs a script it uses a non-interactive shell, which means it doesn't execute files like ~/.bashrc or ~/.bash_profile. This means it uses the default environment and default command search path.

Moreover, it is a best-practice for shell scripts to use absolute paths for command executables so the script will always execute the one you intended, instead of relying upon the search path, which is primarily meant to be a convenience for interactive use of the shell. To discover the absolute path to the convert command, run which convert in a shell.