1

Is there an image editor for OS X (e.g. Preview) that can be operated programmatically, preferably with python, or that has a built-in programming language, like MS Word has VBA built-in (at least on Windows systems)?

I'd like to be able to do the following with code:

  1. Open an image in the image editor,
  2. Use the editor to save the image to some arbitrary location in the file system.

It is essential for me to save the file via the editor, since when the editor saves a file it does more than simply save it: it also writes meta info, which I am interested in.


macOS Sierra Version 10.12.4

2
  • Does the image editor need a GUI? Would a command line image editor be suitable?
    – grg
    Commented Apr 16, 2017 at 9:48
  • @grgarside: I dunno. I can certainly give it a try.
    – Evan Aad
    Commented Apr 16, 2017 at 9:50

2 Answers 2

1

Preview supports AppleScript which allows you to open and save files from CLI. There are commands for open and save.

For example, to open a file with Preview:

tell application "Preview"
    open "/path/to/file.png"
end tell

You can run AppleScript as a script file, or from the command line using osascript -e "…".

osascript -e "tell application \"Preview\"" -e "open \"/path/to/file.png\"" -e "end tell"

You can find the full Preview AppleScript dictionary by opening Script Editor.app (from the Utilities folder), choosing File → Open Dictionary and selecting Preview. This will show you many of the commands that Preview supports with the syntax for how to use them.

2
  • Thanks. This looks terrific. Do you have any suggestion where I can learn more about AppleScript? I don't even understand what you mean by osascript -e "…". Like, what am I supposed to substitute "..." with? How did you get to the screens whose screenshots you included in your answer?
    – Evan Aad
    Commented Apr 16, 2017 at 10:00
  • 1
    @Evan I've edited my answer, let me know if you need anything else.
    – grg
    Commented Apr 16, 2017 at 10:05
1

You can edit image files with Imagemagick cli.

This doesn't present a GUI, but rather provide commands for working with image files directly. There are a plethora of features to support complex editing.

You can install this using Homebrew:

brew install imagemagick

For a full list of functionality, see imagemagick.org or python.org ImageMagick wiki

1
  • Or you could try the built-in CLI image editor, sips (Scriptable image Processing System).
    – calum_b
    Commented May 15, 2017 at 17:25

You must log in to answer this question.

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