Thank you Much Appreciated
This is a very good start…
Thank you Much Appreciated
This is a very good start…
How can I execute these in Execute a Shell Script I have tried and always have message.
Directly in terminal no problem....
I think I'm missing something.. I'm sure... "I'm no programmer"
Thank you very much,
“command not found” indicates the shell is not finding the command, which happens because the PATH is not set correctly.
See the wiki troubleshooting section.
Have tried almost everything...
It is the command that cannot be found.
You have installed it, and it is not somewhere the system can find it without specifying the full path to the command or specifying the search PATH environment variable.
you have to set KM’s
ENV_PATH variable so that KM can find the command.
Yesterday I troubleshooted an analog problem with another user, so this series of posts may be helpful for you:
If you did install
exiftool not with Homebrew, then find out the path(s) of your exiftool by executing this in the Terminal:
type -a exiftool
…and use the correct path as shown in the posts.
This stuff confuses all shell scripting newbies.
Unix systems (and others) use an environment variable ($PATH) to keep track of where to look for executables when they are called by name.
A basic path might look like this:
Mine on the other hand has had several things added to it.
If you want to be able to call
exiftool by name it MUST be within the path, so Unix can see it.
Here’s where my copy of
exiftool is installed:
You can always call a Unix exe by using its full-path.
/usr/local/bin/exiftool -s ~/Downloads/test.jpg
I have a Keyboard Maestro variable called ENV_PATH set to:
That lets Keyboard Maestro see everything in the given paths, and it doesn’t change my system $PATH variable.
So I can call
exiftool from Keyboard Maestro without monkeying around.
exiftool -s ~/Downloads/test.jpg
Alternatively you can set the path when you call your shell script:
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin$PATH; exiftool -s ~/Downloads/test.jpg
This is what I used to do before I started using Keyboard Maestro’s ENV_PATH variable.
Hopefully I’ve clarified things a bit instead of adding to the confusion.
OMG! WOW! Thank you @ccstone This helps so much! It’s like magic…
Now I’m flying now… Whoohoo!
File name has space or spaces Shell don’t like spaces I have searched for a fix and I was unsuccessful.
From my understanding I should replace the space with & right?
Then quote the file names or paths:
exiftool ~/"my file/path with/spaces/my image.png"
You can escape spaces with the backslash
exiftool ~/my\ file/path\ with/spaces/my\ image.png
You are mixing curly quotes and straight quotes. What you need are straight quotes.
The one in the red circle is a curly quote (wrong), the green one looks like a straight quote (OK):
Concerning the different types of quotes, see also my post here.
I guess the curly quote was produced by the system’s Smart Quotes feature.
When editing in KM Editor it’s probably a good idea to disable Smart Quotes (KM Editor > Edit > Substitutions > uncheck Smart Quotes):
Or disable it globally in System Preferences > Keyboard > Text.
Search the Forum for “smart quotes” to find posts about related issues.
Yes, sorry, I didn’t pay enough attention to the whole macro:
In the variable definition do not quote the path at all.
Then in the script quote the KM variable (with straight quotes):
exiftool -s "$KMVAR_PathStr"
~ shorthand from the variable definition, because…
~when quoting the path-containing variable afterwards.
The tilde (
~) is a shorthand for
$HOME, which in your case is
So, if you’re saying
~/Users/imac_willie you are actually saying
/Users/imac_willie/Users/imac_willie, which is wrong of course.
However, you could say
~/Desktop/brush 01-03-17 01.png, but as mentioned above, this will not work when quoting the variable afterwards (
If you want to use the tilde in the variable definition, you can add a Filter Variable action with “Expand Tilde in Path”. So, for example, this will work:
Or, with the fully expanded path (without
~), it works without Filter Variable action:
Added to the wiki:
It is generally a good idea to surround your variable with double quotes in a shell script, for example:
so that it will work properly if the path contains spaces. So if it might contain a ~ at the front, use the Filter Variable, Expand tilde (~) paths action to expand it to a full path first.
I would go so far as to say that you’re foolish if you don’t do this on a Mac – it’s a best-practice kind of thing.
Rule-of-the-thumb – always use $HOME-based (tilde) paths when possible – this makes them safer and more portable.
Keyboard Maestro’s own actions understand the tilde-path notation perfectly well.
If you’re going to use the variable later in a shell script – always follow the Set Variable to Text action with with a Filter Variable ‘yourVariable’ with Expand Tilde In Path action.
When writing shell scripts that utilize a tilde-path with spaces in it the path string must be quoted appropriately:
~/'Downloads/test file with spaces in file name.txt'
You cannot quote the ~/ portion of the path string, but you can quote the entire string after that.
For me personally this reads much better than escaping the spaces.
The shell script:
myPathStr=~/'Downloads/test file with spaces in file name.txt' echo "$myPath"
/Users/yourUserName/Downloads/test file with spaces in file name.txt
The shell interprets the tilde-path at the time the assignment of variable
myPathStr takes place, so the variable itself never sees the tilde part of the string.
This interpolation cannot happen if the path string is already in a variable – as in the case of an assigned Keyboard Maestro variable.
So if your
myPathStr variable in Keyboard Maestro is assigned a string like this:
~/Downloads/test file with spaces in file name.txt
So use that tilde-expansion filter in your macro.
On the other hand if you just have to make the tilde-path work in the shell it can be done (in Bash at least) by using Bash parameter expansion (and other methods):
For more information see: