Skip to content

Instantly share code, notes, and snippets.

@ucchyocean
Last active April 6, 2016 09:03
Show Gist options
  • Save ucchyocean/1aa639db9762d97f419cce843d19f96a to your computer and use it in GitHub Desktop.
Save ucchyocean/1aa639db9762d97f419cce843d19f96a to your computer and use it in GitHub Desktop.
argvが未定義状態?になって、AppleScriptが動作しない件について
test.applescript を、
osacompile -x -o test.app test.applescript
のようにあらかじめコンパイルしておき、test.app を配布している。
OS X 10.8 ~ 10.11 では、
osascript test.app
osascript test.app test
などのように実行して、引数がある時、無い時、いずれも想定通りに動作している。
OS X 10.7 では、osascript test.app を実行すると、
 Execution error: No user interaction allowed. (-1713)
のようなエラーになってアプリケーションが動作しない。
そこで代わりに、
 open -W test.app
 open -W test.app --args test
のように実行しているが、これだと
 length を取り出すことができません。
というエラーで動作しない。
おそらく5行目が問題で、argv が null なのが問題なのだろうか・・・?
on run argv
set PARAMETER to "default"
if length of argv > 0 then
set PARAMETER to item 1 of argv
end if
display dialog PARAMETER
do shell script "echo parameter is " & PARAMETER & ". > /tmp/result.txt"
end run
@ucchyocean
Copy link
Author

OSX10.7 で、osascript で実行したときに「Execution error: No user interaction allowed. (-1713)」が出るのは、AppleScriptの11行目の「do shell script ... 」のあるなしに関係しているようだ。

@ucchyocean
Copy link
Author

とりあえず、下記のように、try ~ on end ~ end try で囲むと解決する。(これが最良の方法なのかどうかは、結局よくわからない。)

on run argv

  set PARAMETER to "default"
  
  try
    if length of argv > 0 then
      set PARAMETER to item 1 of argv
    end if
  on error
    set PARAMETER to "empty"
  end try
  
  display dialog PARAMETER
  
  do shell script "echo parameter is " & PARAMETER & ". > /tmp/result.txt"
  
end run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment