Multiple Paths in one Variable

Hi,
I want to store multiple paths in quotes in one variable to use them in a shellscript command later on in the macro. Use case is to concatenate different PDF-Files via pdftk. The quotes seem to be ignored by the shell script though as if they were curly quotes or something like that. I copypasted them from another working shell script command, though, so I cannot understand why this happens.

Here's what I do:
Append Variable “allPaths” with Text “"%Variable%einzelpfad%" ” //several times
Execute Shell Script: pdftk $KMVAR_allPaths cat output "$KMVAR_tempFolder/output.pdf"
Result is always an error "Failed to open PDF file: [path broken at space]"

Any ideas will be appreciated!

As written in the lengthy documentation of the Execute Shell Script action (action:Execute a Shell Script [Keyboard Maestro Wiki] - paragraph "Quoting Strings"), it says:

So variables that are meant to be a single parameter should be surrounded by double quotes in the line, but not contain quotes in the variable, and generally you do not want to pass multiple parameters within a single parameter.

Sorry, but I fear that actually, that's exactly what I do want! I found that it works if I write the stuff to a .sh textfile before and then execute that one (don't forget to set permissions +x) instead of using the action's text window.

If you have other ideas to manage this, I'm still interested!

The general recommendation is to construct your shell command completely in a single variable and execute the variable. This minimizes the quoting problem you're having.

You can construct your argument list using single quotes around each path ('like this') or by escaping spaces (like\ this) and appending them to your command (perl '/Users/you/Documents/ myTools/convert.pl' ):

perl '/Users/you/Documents/ myTools/convert.pl' '/Users/you/Documents/Working Files/one.txt' '/Users/you/Documents/Working Files/two.txt'

2 Likes