Possible bug in Execute Shell Script Action

A few days ago I wrote myself a plugin to choose a file and have the path to the file returned as either posix, quoted posix or hfs path. Unfortunately it didn't work at least it didn't with the shell script macro I was writing, however it worked fine via Applescript. After beating my head against it for a couple of days I discovered the problem was the "Execute a Shell Script" action. It will not work (OMM) if there is a space or spaces in a path, doesn't matter how it's quoted or escaped, it fails. The solution was to use the "Execute an Applescript" action with its "do shell script" command.

You will need a folder on your desktop named "Text Files" and an empty text file inside it named "test file.txt" for testing purposes.

Here is a demo macro if you wish to test it out. Bug in execute shell script.kmmacros (4.7 KB)

and a look at the macro itself:

Hey John,

There's not a bug in the Execute a Shell Script action. You just need to understand how to use Keyboard Maestro variables properly within one.

No bug in execute shell script.kmmacros (2.2 KB)

See the Execute Shell Script section of the wiki.

A variable in a text field is properly denoted by: %Variable%pathName%

But that does not work in an Execute a Shell Script action – $KMVAR_pathName is the proper format.

And to manage spaces within such a variable you need to double-quote it:

"$KMVAR_pathName"

You have to properly manage spaces in paths within do shell script commands in AppleScript too, and the best method is to use quoted form of.

do shell script "open -t " & quoted form of pathname

-Chris

2 Likes

Chris,

Thanks, I was hoping someone would point out what I missed. :slight_smile:

1 Like