1

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!

  • Where is convert (a guess is that you have set path only in the bash startup files) – Mark Nov 19 '15 at 19:41
  • 2
    Try including full path to 'convert' in your command (as suggested by Jonathan). – Trellis Nov 19 '15 at 19:52
  • @Mark I believe 'convert' came with ImageMagick which is located at /Users/*MY USERNAME*/ImageMagick-6.9.0-3 – Jonathan Nov 19 '15 at 19:52
  • 1
    Why in the last line of the code you posted you're copying the file to the Trash? IMO It makes no sense to copy the file to the Trash. – user3439894 Nov 19 '15 at 20:05
  • 1
    NOTE: Quote your variable expansions unless you are certain they will never contain spaces or other characters that will be interpreted by the shell. In particular, although you hard-code INK to a known pathname without spaces, all your uses of ~ may expand to a path containing spaces. – Chris Page Nov 28 '15 at 13:26
1

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.

  • This should be the accepted answer. I almost downvoted it because there toward the end, I thought you were suggesting to use which convert in the shell script, rather than simply the shell. That threw me for a loop for a second, because my brain didn't interpret it correctly at first. – rubynorails Nov 28 '15 at 13:43
  • 1
    @rubynorails: I've updated the phrasing. – Chris Page Nov 28 '15 at 13:48
0

@Chris Page offered a perfectly acceptable answer, because it addresses all of your necessary issues, but then I took a second look at your code and wondered why not use a function with a loop instead of all those variable commands?

ink() {
  square_dimension="$2"
  infile="$1"
  /Applications/Inkscape.app/Contents/Resources/bin/inkscape --export-png "${root}/test_${square_dimension}.png" -w ${square_dimension} -h ${square_dimension} "$infile"
}

for i in {256,128,64,48,40,32,24,16}; do ink "$1" "$i"; done

Note that the above code has not been tested, and it is not your complete script, just a snippet that will replace the majority of your code. I will update after I have had a chance to test it, but it looks good to me. You may need to export the function or something (export -f ink) or mess around with the argument variables -- but like I said, I will post an update after I've had a chance to test it.

Also, like I said before, @Chris Page offered an answer that pretty much answers your question. This is simply additional info that is better formatted as an answer rather than multiple comments.

Also, it's best practices to always use lowercase variable names in shell scripts so as not to overwrite any of the built-in environment variables (which is something that I have struggled with, because the variables are so much easier to recognize -- especially in a large script on a system without a colored terminal for syntax highlighting).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .