Shell environment

I expect there are aspects of this related to being Sandboxed (which Keyboard Maestro is not, I assume). Documentation for NSUserUnixScript is a bit scant. It was added specifically to support running a script outside the Sandboxed process in user space, but it does not really go into how it creates the environment used…and it does not support, as best as I’ve been able to ascertain, modifying the environment prior to execution.

I can get your result to work if setup the environment in bash and then run the python, like:

let script = `#!/bin/bash
export PATH=/b/foo:$PATH
python -c "import sys;print('.'.join(str(x) for x in sys.version_info[:3]))"
`;
let runner = ShellScript.create(script);

if (runner.execute(["1", "2"])) {
	alert("STDOUT:\n" + runner.standardOutput);
}
else {
	alert("STDERR:\n" + runner.standardError);
}

I think the basic environment is the same or similar to what you would get using do shell script in AppleScript, which is also not loading in any bash_profile info, etc.

1 Like