Batch convert .ai to .svg using Mac Terminal
Asked Answered
L

3

6

I have a folder that contains thousands of .ai files and I want to batch convert them to .svg files using Mac terminal.

Until now I did it through Adobe Illustrator but it takes days to batch convert .ai to .svg.

Is there any way to do it through the Terminal?

P.S. Keep in mind I am not a software developer but a regular user, so please explain as simple as possible with details, otherwise I will get lost and I will need further instructions :)

Thanks

Lilybelle answered 7/4, 2016 at 19:4 Comment(1)
You meant to use the [batch-processing] tag.Filmore
K
6

Inkscape has some great command line tools for this. Check out their wiki page on this.

Their python script ai2svg.py looks like it should do the trick. Try the following command:

find . -name "filename*" -exec python ai2svg.py '{}' \;

Replace filename* with the matching filename(s) that you want to work on. To learn more about executing commands on multiple files see this post.

Hope this helps!

Kellyekellyn answered 7/4, 2016 at 19:17 Comment(0)
K
5

The ai2svg.py script suggested by Mikel hangs for me, but it seems Inkscape can be invoked from Terminal directly and does the job well:

Save the following script as a file ai2svg, make it executable via chmod +x ai2svg then run it, optionally passing the folder to look for Illustrator files.

It will convert in that folder, or the current one, all .ai files into .svg

#!/usr/bin/bash

createsvg() {
  local d
  local svg
  for d in *.ai; do
    svg=$(echo "$d" | sed 's/.ai/.svg/')
    echo "creating $svg ..."
    inkscape -f "$d" -l "$svg"
  done
}

if [ "$1" != "" ];then
  cd $1
fi

createsvg

source: https://gist.github.com/WebReflection/b5ab5f1eca311b76835c

Kazoo answered 4/10, 2017 at 16:52 Comment(2)
Worked for me. But seems you forgot to mention, there should be inkscape installed to succeed. Here is useful link to install inkscapeSwinford
I had to add d=$(echo "$(cd "$(dirname "$d")"; pwd)/$(basename "$d")") as the first line of the for loop to make the path to $d absolute, otherwise inkscape just erred that it couldn't find the file.Betts
M
1

This is inspired by the21st's version. It converts files specified on the command line, so it can handle individual files as well. As the original question mentioned bulk work, space could be an issue, so this script compresses the generated svg. In my case, this results in a 90-95% space saving compared to the original .ai files.

#!/bin/sh

set -e

for file in "$@"
do
    case "$file" in
        *.ai|*.AI)
            outfile=$(echo "$file" | sed 's/.ai/.svg/i')
            zoutfile=$(echo "$file" | sed 's/.ai/.svgz/i')
            if [ -e "$outfile" -o -e "$zoutfile" ]; then 
                echo "'$outfile' already exists, skipping"
            else
                inkscape --file="$file" --export-plain-svg="$outfile"
                gzip -9 "$outfile"
                mv "$outfile".gz "$zoutfile" 
            fi
            ;;
        *)
            echo "'$file' does not have an .ai extension, skipping"
            ;;
    esac
done
Meade answered 8/12, 2019 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.