Skip to content

Instantly share code, notes, and snippets.

@uchcode
Created July 12, 2017 14:27
Show Gist options
  • Select an option

  • Save uchcode/5f5b4190426d72f4dfa46fd26d363d97 to your computer and use it in GitHub Desktop.

Select an option

Save uchcode/5f5b4190426d72f4dfa46fd26d363d97 to your computer and use it in GitHub Desktop.
JXA DoShellScript
const DoShell = (()=>{
const app = Application.currentApplication()
app.includeStandardAdditions = true
function doShell(script, opt={}) {
return app.doShellScript(script, {
administratorPrivileges: !!opt.withPrompt,
withPrompt: opt.withPrompt || '',
alteringLineEndings: opt.alteringLineEndings || false
}).replace(/\n$/,'')
}
function sh(script, opt={}) {
try { return doShell(script,opt) } catch(e) {
return ''
}
}
function test(arg) {
try { return !!doShell(`test ${arg}`) } catch(e) {
return false
}
}
return {
doShell: doShell,
sh: sh,
test: test,
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment