How to pass a variable to "do shell script" in Execute Applescript action?

I have a macro which will figure out which of my external disks to back up to, depending on day of week, and then set TimeMachine in motion on the right disk, via an Execute Shell Script action which contains "do shell script "tmutil startbackup -d diskID"". However, I can't figure out how to get the diskID into that string! I've tried preforming the entire string (including the do shell script part) in another variable, but that doesn't work either.
How can I pass the diskID value into a do shell script command inside Execute Shell Script?

It would be very helpful to upload your actual macro so we can see it to help debugging.

For one thing do shell script is AppleScript language, so if you are using Keyboard Maestro's Shell Script action, then you do not want to use that.

See Using KM Variables in an Execute a Shell Script action

But @tjluoma is right, it looks like you do not have the Execute Shell Script setup properly. The above link will also provide general info on how to use Execute Shell Script Actions.

My sincere apologies, I wrote the wrong thing yesterday. I am not using Execute Shell Script, I am using Execute Applescript!!! :blush:

My macro is a little long so I have exported a short one that just does the actions we're interested in. When I run it, I get to the Growl, but the backup does not start. (The disk in question is mounted on my desktop)

Untitled.kmmacros (1.9 KB)

Untitled.tiff (113.9 KB)

I had a look at Execute Shell Script but in my KM there is no way to specify the input for it, so I would prefer to use Execute Applescript if possible.

This does not make any sense to me. There are many ways to pass a KM Variable to a Shell Script.

But if you need to use AppleScript, then a script like this should work.
Note: I have NOT tested this script, since I don't have your diskID.

tell application "Keyboard Maestro Engine" to set diskID to getvariable "DiskID"

set cmdStr to "tmutil startbackup -d " & diskID
set shellResults to do shell script cmdStr

return shellResults

Thank you so much!! This works perfectly.

BTW, indeed there is no way to pass anything to my KM's Execute Shell Script action:
Untitled1.tiff (19.7 KB)
Untitled

Thanks again :slight_smile:

As linked to in the Help for that action, or by @JMichaelTX above, the help from Execute a Shell Script action shows how to access Keyboard Maestro variables from a shell script as environment variables.

Keyboard Maestro 9 also lets you send stdin, but that's probably not what you would do in this case anyway.

Thanks Peter, I see the section you mean but I am not very confident (at all!) with shell scripting.

No, that's correct.

Thanks for your reply, though :slight_smile:

Most of us learn best by examples. To see some good examples of using shell scripts with KM, just do a Forum tag search on "shellscripts".