2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

runScript() のwithParametersバグとその回避・代替案

Posted at

runScript()でオプションwithParametersを使用すると原因不明のエラーが発生する。詳細は不明だがrun()の返値の型が問題だと推測される。原因は何であれ現状はこのバグを回避するには例外処理するかdoShellScriptosascriptコマンドを代替とする。

foo.scpt
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(' ')}`)
bar.scpt
function run(argv) {
  $.NSLog('%@', JSON.stringify(argv))
  return argv
}
2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?