I can certainly understand Chris's preference for compiled scripts, but FWIW, from the Javascript perspective, there may be a couple of general advantages to using a shell script:
- KM_VAR values are easily read in the shell
- If you are writing reusable code (text etc) you can use a javascript module pattern to keep the KM part separate from the rest of the code, in case you want to use your .js on iOS or elsewhere.
( but 2 is probably not relevant here : - )
#!/bin/bash
osascript -l JavaScript <<JXA_END 2>/dev/null
(function (v) {
var a = Application.currentApplication();
a.includeStandardAdditions = true;
a.setVolume(null, {
outputVolume: v
});
})($KMVAR_VOLUMESTATE);
JXA_END
Rob