PNG Metadata "Comment"

Thank you :slight_smile: Much Appreciated :slight_smile:

This is a very good start… :slight_smile:

1 Like

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" :slight_smile:

Thank you very much,
Bill

“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.

Ie, exiftool

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.

Hi Bill,

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.

Thank you @peternlewis and @Tom Have it working now...

Hey Bill,

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:

/usr/bin:/bin:/usr/sbin:/sbin

Mine on the other hand has had several things added to it.

/opt/local/bin:/opt/local/sbin:/Users/myUserName/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

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:

/usr/local/bin/exiftool

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:

/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

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.

-Chris

3 Likes

OMG! WOW! Thank you @ccstone This helps so much! It's like magic.. :slight_smile:
Now I'm flying now... Whoohoo!

1 Like

Thanks for that. I see @JMichaelTX has already added some of the info to the Execute a Shell Script action page on the wiki, and I added a little more as well.

1 Like

I'm flying now... oops I hit a wall....

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?

Much appreciated,
Bill

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
1 Like

Wow... I'm Missing something... Not working.. I feel so LAME

:frowning:

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.

PS:

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.

1 Like

Still no change

WOW it looks like the file name is being broken down into three... ?

Spaces maybe?

Yes, sorry, I didn’t pay enough attention to the whole macro:

  1. In the variable definition do not quote the path at all.

  2. Then in the script quote the KM variable (with straight quotes):

exiftool -s "$KMVAR_PathStr"

Important:

Delete the ~ shorthand from the variable definition, because…

  • It makes no sense here, since you are already giving the whole path from root level (/Users/…)
  • In general you can’t use the ~ when quoting the path-containing variable afterwards.

FYI:

The tilde (~) is a shorthand for $HOME, which in your case is /Users/imac_willie.

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 ("$KMVAR_PathStr").

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:

1 Like

It works

Fine :relieved:

1 Like

Added to the wiki:

It is generally a good idea to surround your variable with double quotes in a shell script, for example:

cat "$KMVAR_File_Path"

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.

1 Like

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.

But...

If you're going to use the variable later in a shell scriptalways 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"

Outputs:

/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
cat "$KMVAR_myPathStr"

Will fail.

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):

cat "${KMVAR_myPathStr/#\~/$HOME}"

For more information see:

How to manually expand a special variable (ex: ~ tilde) in bash

BashGuide/Parameters

-Chris

2 Likes