2

I'm trying to write automation service that gets all images exclude .jpg from the current directory (or selected files), convert them to .jpg by imagemagick mogrify and delete old images.

script: mogrify -format jpg *.* && find . -type f ! -name "*.jpg" -delete

I've tried my script in the terminal and it works fine.

Then, I've created automator service for doing the same thing from context menu and I'm stacked.

automator script

It make error

The action “Run Shell Script” encountered an error: “zsh:1: command not found: mogrify”

UPD.

Thanks to Mark Setchell, /opt/homebrew/bin/magick works fine, but i'm still having errors that you can see below. Looks like the script executing in the incorrect folder.

enter image description here

UPD2.

I fixed it by passing input as argument and using this argument (folder) for changing directory before script

enter image description here

Lirrr
  • 377
  • 1
  • 2
  • 6

2 Answers2

3

As you are on a Mac, you probably installed via homebrew, so ImageMagick binaries are likely in /usr/local/bin or /opt/somewhere.

You can use this command in Terminal to find it:

find /opt /usr -name magick

So if you find /opt/somewhere/bin/magick, use:

/opt/somewhere/bin/magick mogrify ...

in your script.


Prior to v7, ImageMagick had lots of commands in its suite - convert, mogrify, compare, compose, animate, conjure, display and so on. In v7, all commands were prefixed with magick so there is just one command and "the namespace is less polluted" as some folks call it. The convert command also used to clash with some Microsoft CONVERT.EXE thing on Windows that converts filesystems from one format to another.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • `/opt/homebrew/bin/magick` works, thank you! Unfortunately i got another error. Looks like it tried to convert inside incorrect folder. The action “Run Shell Script” encountered an error: “mogrify: no decode delegate for this image format `LOCALIZED' @ error/constitute.c/ReadImage/741. mogrify: no decode delegate for this image format `SH' @ error/constitute.c/ReadImage/741. – Lirrr Mar 03 '23 at 08:34
  • Try printing the name of the image. I guess you are trying to convert a file that isn't an image. *"Can't decode"* means it is an unreadable format. – Mark Setchell Mar 03 '23 at 08:40
  • You can use `magick mogrify -verbose ...` too. – Mark Setchell Mar 03 '23 at 08:42
  • I've updated the question. As you can see, there are only images – Lirrr Mar 03 '23 at 08:52
  • Your script is likely running in a different directory from where you think - it is reading JSON, PHP, shell and LOG files. Try printing the directory with `pwd`. – Mark Setchell Mar 03 '23 at 08:57
1

You need to prepend 'magick' to the command. If you've added ImageMagick as an environment variable, that will suffice. If you have not, you need the path to the magick executable.

Zita
  • 121
  • 1
  • 9
  • I've tried magick and got error too `The action “Run Shell Script” encountered an error: “zsh:1: command not found: magick`. How can i find the path to the magic executable? – Lirrr Mar 03 '23 at 08:07