SOLVED - KM: Use user input variable in shell script

I am a KM novice. On my Mac I keep an SSD plugged in at all times but not always mounted. I want to use KM to mount the SSD. I tried this and it woks well:

I want to use user input to ask for password before mounting. I don’t know how use a variable in place of the password “dingus”. Here is my user input:

I tried many things and none of them worked. Any help is appreciated.

Try to look at the wiki page for Execute Shell Script.

1 Like

Looked at this and still was not able to find a solution. I have since found out that what I want to do is not possible. Thanks for your suggestion. :grinning:


It should be possible.

Do not know if your command works in Terminal if you run it manually.

If it does then your macro should have the prompt for user input before the execute shell script.

And the command in the execute shell script should be:
diskutil apfs unlockVolume disk9s1 -passphrase $KMVAR_Enter_password

But remember that the variable Enter password is saved in KM as a variable other macros can access. Best to have at as a local variable for just this macro. Or use the KM action to get the password from the keychain.

Thanks for following up on this. Your response really got me thinking more about this problem and I have figured out what was wrong. I really appreciate your help.

This is how my KM macro was written.

In all of my testing I was using the same variable, “Enter_password”. Then I tried just simply, “pw”. Neither of these worked. Finally, I tried just the word “phrase” as a variable and it worked fine. After all of this I searched the KM Wiki and came across this. (I know I should have looked here first but I didn’t. I think I was so excited to make my first macro, that I just pressed forward. Oh, well.)

Here is the KM Wiki pages on Variables where this came from.

Thanks for this suggestion. Now my goal is to learn how to use a local variable for my macro, as I don’t want the password for this drive showing up in the KM Variables Preference Pane.

Eventually I want to figure out if I can use the actual name of the SSD instead of “disk5s1”.

I do not think you, in this case, needs to define any input to the Execute Shell Script action.
Maybe it does more harm than good in this case.

If a variable is defined before the shell script you can use it with the $KMVAR syntax.
I think the with input from passes these paramters to STDIN to the script, but I have not read up on this.

1 Like