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
| function nodejs(fn,lp='/usr/local/bin/node') { | |
| let code = `console.log(JSON.stringify((${fn.toString()}).apply(null,JSON.parse(process.env.NODE_ARGS))))` | |
| let data = $(code).dataUsingEncoding($.NSUTF8StringEncoding) | |
| return function(...args) { | |
| let i = $.NSPipe.new | |
| i.fileHandleForWriting.writeData(data) | |
| i.fileHandleForWriting.closeFile | |
| let o = $.NSPipe.new | |
| let e = $.NSPipe.new | |
| let t = $.NSTask.new |
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
| on readline(theFile) | |
| return read theFile before "\n" as «class utf8» | |
| --return read theFile before return as «class utf8» | |
| end readline |
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 General = (()={ | |
| function StringFromData(data=$.NSData.data,encoding=$.NSUTF8StringEncoding) { | |
| return $.NSString.alloc.initWithDataEncoding(data,encoding).js | |
| } | |
| function StringToData(value='',encoding=$.NSUTF8StringEncoding) { | |
| return $(value).dataUsingEncoding(encoding) | |
| } | |
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 |
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 FileManager = (()=>{ | |
| function pwd() { | |
| return $.NSFileManager.defaultManager.currentDirectoryPath.js | |
| } | |
| function cd(path='~') { | |
| if (path==='') path = '.' | |
| let p = $(path).stringByStandardizingPath | |
| let r = $.NSFileManager.defaultManager |
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
| function app_read(handle, scpt='') { | |
| let a = Application.currentApplication() | |
| a.includeStandardAdditions = true | |
| return a.runScript(`on run argv | |
| read (item 1 of argv) ${scpt} | |
| end`, {in:'AppleScript', withParameters:handle}) | |
| } | |
| app = Application.currentApplication() | |
| app.includeStandardAdditions = true |
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
| ChocoFileManager = { | |
| pwd() { | |
| return $.NSFileManager.defaultManager.currentDirectoryPath.js | |
| }, | |
| cd(path='~') { | |
| let p = $(path).stringByStandardizingPath.js | |
| let r = $.NSFileManager.defaultManager.changeCurrentDirectoryPath(p) | |
| if (!r) { | |
| throw new Error(`cd(): No such file or directory: "${path}"`) | |
| } |
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
| Applet = Application.currentApplication() | |
| Applet.includeStandardAdditions = true | |
| function sh(script, opt={}) { | |
| return Applet.doShellScript(script, { | |
| administratorPrivileges: !!opt.withPrompt, | |
| withPrompt: opt.withPrompt ? opt.withPrompt : '', | |
| alteringLineEndings: opt.alteringLineEndings ? opt.alteringLineEndings : false | |
| }).trim() | |
| } |
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
| class PathItemObject { | |
| constructor(path) { | |
| if (!path) throw new Error('PathItemObject: The argument "path" is required.') | |
| if (Object.prototype.toString.call(path).slice(8,-1).toLowerCase()!=='string') throw new Error('PathItemObject: The argument "path" must be a string') | |
| this.pathString = path | |
| let $p = $(path).stringByStandardizingPath.js | |
| if (/^\//.test($p)) { | |
| this.path = $p | |
| } else { | |
| this.path = $($.NSFileManager.defaultManager.currentDirectoryPath.js + '/' + $p).stringByStandardizingPath.js |
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
| fm = $.NSFileManager.defaultManager |