Last active
April 6, 2016 09:03
-
-
Save ucchyocean/1aa639db9762d97f419cce843d19f96a to your computer and use it in GitHub Desktop.
argvが未定義状態?になって、AppleScriptが動作しない件について
This file contains 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
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 なのが問題なのだろうか・・・? |
This file contains 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 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 |
とりあえず、下記のように、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
OSX10.7 で、osascript で実行したときに「Execution error: No user interaction allowed. (-1713)」が出るのは、AppleScriptの11行目の「do shell script ... 」のあるなしに関係しているようだ。