Help With Image Manipulation and Variables

Hi guys

so i tried this macro below to use CLI image magic to process an image

I'm trying to whiten an image and the command needs a input image and an output image specified. I want to add a character (like '2') after the filename and before the extension. I'm sure its simple and I'm an idiot.

Can someone guide me on this?

thx

Z

Hey Z,

In such cases please provide the macro file (or actions file) associated with the image, so people don't have to reinvent the wheel to help you.

Please also provide a working sample of the shell script you're using that you've tested in the Terminal (if you have one).

Observations:

  1. Change the “File” variable name in the for-each action to filePathStr, so something more evocative of what it really contains.

  2. You're monkeying around with file-name and file-extension, when you've failed to tell your shell script where to look for files. You need the script to cd change directory to the container directory of the file(s) to be processed (OR you need to provide full paths).

  3. Use a Keyboard Maestro environment variable (ENV_PATH) to set the path for shell scripts run from KM ($PATH).

Mine looks like this:

/opt/local/bin:/opt/local/sbin:/Users/chris/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin

Running this FROM Keyboard Maestro will get you something close to what you need.

Execute a Shell Script.kmactions (661 B)

Shell Script for Above Action
printf "/usr/local/bin:$PATH"
  1. It's not a good practice to compose your command line IN a Execute a Shell Script action. This practice is fraught with opportunities for failure (or disaster) and is very difficult to debug.

  2. It's a better practice to compose your shell script in a variable, so you can safely run the macro and eyeball the script before actually running it.

Compose a Shell Script Before Running It v1.00.kmmacros (7.9 KB)

  1. Be sure to get your command running correctly in the Terminal, before even beginning to work with Keyboard Maestro and variables.

If you're still stuck then holler.

-Chris

thx @ccstone, appreciate the detailed response

I will look into all the tips you gave. One thing I didn’t make clear was that I'm trying to launch the CLI on the currently selected finder files so I assume I don't need the cd step.

thx

Z


P.S. This is my current in progress macro :slight_smile:

Whiten image .kmmacros (3.6 KB)
image

Hey Z,

That requires using the path and not just the name and file extension.

For commands like this it's much safer to cd into the target directory and use the file name-extension instead of the full path. You're much less likely to make a mistake that can destroy something unintended.

ImageMagick's convert command by design cannot edit a file in-place, so the syntax you were using could never work.

To use convert like this you have to provide the source and destination file names (or paths):

cd ~/'test_directory/ImageMagick_Test_Folder/'
convert test.png -fill white -colorize 80% 'test copy.png'

On the other hand ImageMagick does provide a means to edit files in-place.

The command for this is mogrify.

So – this macro follows the intent of the one you posted:

Whiten image.ccstone v1.00.kmmacros (6.3 KB)

-Chris

You can even speak with authority on ImageMagick! Can you make a short list of everything you don't know?

Nyet.

It wouldn't be short and would be too difficult to compile, because even I don't know everything I don't know...  :sunglasses:

By the way – I'm not that knowledgeable about ImageMagick. I've used it for this and that over the years but not that often.

I'm thinking either @mrpasini or @Tom are the likely authorities on this forum.

However – I can research the issue with Google – and read a manual.

-Chris

thx @ccstone
that’s perfect

best

Z