Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save christopheranderton/50d62b8fd7d95c917fa2fdfc3abb6d6a to your computer and use it in GitHub Desktop.
Save christopheranderton/50d62b8fd7d95c917fa2fdfc3abb6d6a to your computer and use it in GitHub Desktop.
Add a ”SVG to EPS Converter” Service to your context menu (Right-Click Menu) in macOS/Mac OS X (Tested in Mac OS X El Capitan 10.11.6, but should work in some older versions and Sierra as well) using Homebrew installed svg2pdf and pdftops (Poppler) with Automator.app

1. What you need

  • macOS/Mac OS X (tested only on El Capitan, but should work on Sierra and older versions)
  • Xcode Command Line Tools / Xcode
  • Homebrew (http://brew.sh/)
  • svg2pdf (via Homebrew)
  • Poppler (via Homebrew)

2. Installing Homebrew, svg2pdf and Poppler

  1. For installing Xcode and Command Line Tools. Please see: http://railsapps.github.io/xcode-command-line-tools.html
  2. Open up your Terminal.app (or iTerm.app)
  3. Follow the instructions at http://brew.sh or just Copy Paste: (one line!) /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" to install Homebrew.
  4. Install Poppler (that we need for the pdftops command) by copy paste: brew install poppler --with-little-cms2 (It will install dependencies also, which could take a minute or so).
  5. Install svg2pdf by copy paste: brew install svg2pdf

Short version:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"  
    
    brew install poppler --with-little-cms2     
    
    brew install svg2pdf

4. Creating the Automator.app Service

  1. Open up Automator.app located in your Applications folder.
  2. Choose ”Service” in the dialog sheet when creating a new document.
  3. In the Services receives selected: menu at the top of the ”Canvas” on the right, change to image files and ”in” to Finder.app
  4. In the sidebar to the left, search for Run Shell Script
  5. Drag the Run Shell Script action to the ”canvas” on the right side.
  6. At the right in the Run Shell Script action, change the Pass input from to stdin to as arguments
  7. Copy Paste this into the action text box (remove existing code in the text box):
PATH=/usr/local/bin:/bin export PATH
for f in "$@"
do
svg2pdf "$f" "${f%.*}.pdf";
pdftops -eps "${f%.*}.pdf";
rm -f "${f%.*}.pdf"
done

Save the Service into /Users/yourusername/Library/Services. Test it by select a .svg file in the Finder and Right-Click and go to end at the Context menu labeled ”Services” and look for the name you gave your Service. If everything works alright, .eps versions of the .svg file(s) choosen should appear.

Breakdown

Line 1: PATH=/usr/local/bin:/bin export PATH
Tells where to look for svg2pdf and pdftops
This may not be necessary depending to your enviroment settings.

Line 4: svg2pdf "$f" "${f%.*}.pdf";
Converts the svg-file(s) to PDF. The ; at the end indicates when the command is finished, go ahead and jump to the next command.

Line 5: pdftops -eps "${f%.*}.pdf";
Converts the pdf-file(s) to EPS.
A small workaround. I never managed to get Inkscape (command line) working correctly on macOS/Mac OS X.

Line 6: rm -f "${f%.*}.pdf"
Deletes the pdf file(s) leaving you with the original svg file(s) and the eps files you created.
You could remove this line. That way you have both a EPS version of the svg files(s), and a vector PDF version. Or you could add svg to delete the original files as well (however, i would not recommend that).

Notes

Some conversions could in some cases output .eps file(s) that don't necessarily match the .svg file(s) by 100%. In my tests, most files converted worked out just fine except a few (the eps output itself was correct, but was ”squeezed” a little bit).

Getting creative with naming the Service. You could use a Emoji or Unicode symbol in the beginning of the file name. While it's not best practice in the * -nix or Windows world (or anywhere else), this is Mac only and for your personal use, also it will not give you any kind of problems (if you send it to someone, do zip the file first!). Example: EMOJI - Vector | SVG 2 EPS . Makes it easier to locate in the sometimes crowded ”Services” Contextual menu.

Example (from my SVG2PNG Service):

screenshot


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment