Skip to content

Instantly share code, notes, and snippets.

@uchcode
Created June 22, 2016 10:54
Show Gist options
  • Save uchcode/709943a263aca2db68dc9371ddddb039 to your computer and use it in GitHub Desktop.
Save uchcode/709943a263aca2db68dc9371ddddb039 to your computer and use it in GitHub Desktop.
runScript() のwithParametersバグとその回避・代替案 ref: http://qiita.com/tom-u/items/a9335672f21e91a4a69d
function run(argv) {
$.NSLog('%@', JSON.stringify(argv))
return argv
}
app = Application.currentApplication()
app.includeStandardAdditions = true
argv = ['hoge', 'fuga']
scpt = '/path/to/script/bar.scpt'
// パラメーターを渡すと返値が発生。エラーとなるので例外処理で回避。
// bar.scptからの返値は扱えない。
try { app.runScript(scpt, {withParameters: argv}) } catch(e) {}
// パラメーターも意図通りに渡せて返値も取得可能。
app.doShellScript(`osascript "${scpt}" ${argv.join(' ')}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment