Convert SVG with Inkscape/Bash

Command line tips for the lazy.

I'm not sure if lazy is the right word if one spends a full day in finding out how to automate a small repetitive task that would have cost you half an hour, and you might never need again. Maybe I should rephrase. 'Command line tips for the crazy'. Anyway, this is a mini post for those of you who are not very familiar with bash and the command line, but need to convert lots of svg files to png or psd. (these insctructions are for linux, but should apply to windows too somehow)

Copy and paste the following bash snippet in a text document and name it whatever-you-like.sh (for example).

#!/bin/bash
for var in "$@"
do
	s=${var##*/}
	base=${s%.svg}
	echo 'converting' $var
	inkscape -f $var -e $base.pdf
	echo 'done!'
	echo '*****'
done

Right click the text document and make it executable (or 'chmod a+x whatever-you-like.sh' at the command line, since we're talking about that anyway). It's very handy to make an alias for this sort of custom bash scripts so you wouldn't have to type path and file name every time you need them, but I'm not going into that now. Then cd to your image folder and type

whatever-you-like.sh *.svg

This will convert all svg files in that folder to pdf files with the same name. You can change the script and output to png, ps and eps and it will convert accordingly. Note that you have to either make an alias in your .bash_aliases to call the scripts, or explicitly mention the full path to it in the command like so /path/to/scripts/whatever-you-like.sh *.svg

All info on inkscape command line here: http://inkscape.org/doc/inkscape-man.html

Plain text

  • Geen HTML toegestaan.
  • E-mail- en internetadressen worden automatisch aanklikbaar.
  • Regels en alinea's worden automatisch gesplitst.
By submitting this form, you accept the Mollom privacy policy.