Created
July 12, 2017 14:27
-
-
Save uchcode/5f5b4190426d72f4dfa46fd26d363d97 to your computer and use it in GitHub Desktop.
JXA DoShellScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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