PNG Metadata "Comment"

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