Crop svg files on the commandline in osx

This script saves you a lot time if you have a lot of svg file to process. It fits the page size of the svg file to your drawing (i.e. 0 margin). Here is the code:

#!/usr/bin/env python3

import subprocess
import sys

# for fn in sys.argv[1:]:
#     inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose *.svg
subprocess.call(['/Applications/http://ift.tt/1ijKEPM',
'--verb=FitCanvasToDrawing',
'--verb=FileSave',
'--verb=FileClose'] + sys.argv[1:])



On Linux it’s simpler, you can replace the long string ‘/Applications/http://ift.tt/WUxpis; with ‘inkscape’.