Help With a Macro to Execute a CLI Command on a Finder Folder


im trying to execute a simple macro that will run a command on a folder in finder.

the command is beet import and its supposed to run on a folder

so something like this


ive tried using this

beet import "$KMVAR_Path" after defining a path in For Each Item in a Collection Execute Actions

can anyone point me in the right direction



Can you try it with a simple ls $KMVAR_Path as the shell script action? Does that give you the desires output? (A list of files from all the selected directories.)

If not: what output does this give you?

Thx Martijn!

issuing ls $KMVAR_Path opens a terminal and does ls in the main home folder (~) and not the folder of the current selected folder in finder



Are you executing this macros with Finder in the foreground?

How are you triggering the macro? Shortcut, menu, hitting "try" in KM? (That last one would mean that Finder is not in the foreground, which could be the reason it doesn't work I think.)


i have it set as a status menu item. i focus finder and then press the status menu entry .
I also tried now assigning it a hotkey and launching from finder with no success.



Just a thought… but is "Path" possibly a reserved variable ? Maybe try renaming it to something else.

If that doesn't work, try posting a screenshot of your macro so we can take a closer look?


But this brings up the point that @zeltak needs to post his actual macro (or a simplified example on an actual macro that is failing).

Otherwise everyone is just guessing at that the problem might be. We don't even know if the variable in the For Each action is “Path”, or what collection is being used, or whether their is an issue with the specific execute action being used.

thx again for the answers

i didnt know how to export a macro but now i got it. here it is

Also here is the CLI output i get

zeltak@imbp-50:~|⇒  beet import $KMVAR_Path
error: no such file or directory: /Users/zeltak/music/Moby Grape - Moby Grape 1967/

I think maybe the variable Path dosent get updated after the first time i run it, since i get the same output even if i try to beet import another folder

ie i get the

error: no such file or directory: /Users/zeltak/music/Moby Grape - Moby Grape 1967/

even though the folder im trying to import is


thx alot for all your help guys


Perhaps Moby Grape is where Bash first gets misled by an unquoted space in a path.

To stay on the Bash syntax road, you may need either to escape spaces within paths (Moby\ Grape) or enclose whole paths in bash quotes, for example as in:


thank you!

i tried this but i now get a plain error:

zeltak@imbp-50:~|⇒  beet import “$KMVAR_selectedPath”
error: no such file or directory: “”

this is how the macro looks now



  1. Without the context, we can't see what value you have assigned to $KMVAR_selectedPath – it could be ""
  2. You appear to be using 'smart quote' characters (differing to left and right, “ ” for smartly formatted printing), rather than the plain " " used by the shell.

Aa-ha! it was indeed the smart quotes!!!
its weird because thats the quotes my MBP defaults to when i press it..i come from 15 years of linux so didnt even considered that it could be "smart quotes"..not very smart i guess :slight_smile:

thx so much for your help!


1 Like

For peace of mind, and a bit more control:

System Preferences > Keyboard > Text > Use smart quotes and dashes > Off

(There may well be some other things there which could usefully be switched off or adjusted)

1 Like