Why does executing this script not work the same as in terminal

I wrote a shell script that opens a file in an editor (Emacs) using the shell command 'emacsclient'. It works fine from the command line, but doesn't do anything when I execute it in KM via the "Execute Shell Script" action. From the command line it opens a file or folder in Emacs instantly, but from KM It just silently does nothing.

I verified that other shell scripts work in KM, doing simple things like 'echo' and 'pwd'.

Why would this particular script behave differently in KM?

Update. It works now, sort of. I needed to give the full path to my script. I guess the environment that KM runs it in does not have the same PATH as my terminal

But now I want to change it a little. I want to run a shell script as a "text script" (one of the options KM gives in the Execute Shell Script action") and I want to insert the value of a variable, perhaps %SystemClipboard% or other things, into the script. I noticed that my only option is typing text into that box, and it doesn't interpolate tokens. Is there any way to do this?

Correct. See the documentation on Execute a Shell Script action, particularly the section on Path in Shell Scripts.

Correct, there is no interpolation in the script text, that would frequently lead to disasters.

See the page above, the Using Keyboard Maestro Variables section.

BTW, in the editor when editing the Execute a Shell Script action, in the gear menu, you can select Help, and it will take you to that wiki page.

1 Like