Simple shell script is failing with status 1

Hello, I'm trying to use this seemingly simple macro to eject all my external drives, but when I run it, I get the error "Task failed with status 1 in macro while executing Execute Shell Script." Any suggestions?

Thank you!

For Each.kmactions (1.5 KB)

Keyboard Maestro Export

A search here for something like 'shell failing' will return dozens of hits.

The Execute shell script action provides a fresh vanilla shell instance, without any inheritance from, or knowledge of, your settings (search paths etc) in the shell instance.

Without any defined search paths, you might, for instance, need to specify a full path for diskutil. Check on your system, but here it seems to be /usr/sbin/diskutil

See, in addition to the dense forest of relevant threads here:

action:Execute a Shell Script [Keyboard Maestro Wiki]

PS it's also hard to know from here exactly what that Keyboard Maestro variable name is expanding to.

You can check the available device names by starting with something like:

/usr/sbin/diskutil list

assuming, that is, that on your system a query like:

whereis diskutil

returns a result like:

Thanks for the replies, @ComplexPoint. For the record, I did both read the Wiki and many of the relevant threads before asking for help — and, having used Keyboard Maestro for years, I have a ton of other macros that have successfully used shell scripts before, which is why this one stumped me. Oddly, a very similar macro to mount the drives worked perfectly, but you're right, here it seems like I need to use the full path of diskutil. The script then unmounts all the drives. I still get the error message that the script failed to run, but it is unmounting the drives, at least.

I was able to check what the "$KMVAR_DriveName" is expanding to by adding an "echo" command to the top of the shell script. It expands as expected, to each drive name in succession (as the loop runs).

Have a great day.

1 Like

It's nearly always the search path issue.

For a helpful general approach, see:

Create a PATH Environment Variable for Keyboard Maestro and Add /usr/local/bin to the Default Path - Questions & Suggestions - Keyboard Maestro Discourse

1 Like

I’m not near a Mac, so I can’t check, but some commands return a nonzero status even though they seem to have done what you want. If that’s the case with diskutil, you can avoid the Keyboard Maestro error message by changing one of the settings in the gear menu.

and, of course, if we only want the effects, we can always suffix noisy command lines with redirections like: