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.
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:
Change the “File” variable name in the for-each action to filePathStr, so something more evocative of what it really contains.
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).
Use a Keyboard Maestro environment variable (ENV_PATH) to set the path for shell scripts run from KM ($PATH).
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.
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.
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.
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:
Resurrecting this thread because I'm trying to do something similar, namely converting from jpg to png.
@ccstone I read through all the comments, downloaded your macros and walked myself through them to try and understand them. I would just like to understand the Shell Script itself a little better.
In my test macro below, I am able to successfully set the variables, correct the file path for use in the Shell Script, and then run the SS successfully. I would just like to understand the three different parts of the SS for potential future use. Could you expound on what they do?
Here's what I think they do...
shCmdStr="$KMVAR_debug_shCmdStr" - sets a SS "variable" to whatever the KM variable is? printf "$shCmdStr" - no clue what this does bash -c "$shCmdStr" - obviously runs the command... but why the bash -c? Just to indicate which kind of shell it needs to use?
Sorry for what are no doubt very newbie questions... but you've helped me so much with AppleScript these past few months, and try as I might with Shell Scripts, there are a lot of things I just don't get still.