2012-08-08 6 views
6

「許可ユーザーの操作」を返していない私が使用してコンソールから簡単なメッセージボックスを呼び出そうとしました:のAppleScriptが

osascript -e "display dialog \"hello\"" 

をそれが返されます。

execution error: No user interaction allowed. (-1713) 

は、回避策はありますか?

EDIT:

回避策は次のとおりです。tell application "AppleScript Runner" to display dialog "Hello"

答えて

-6

このanswerを参照してください、それはコンソールから作品例が含まれています。

8

SystemUIServerのようなバックグラウンドプロセスにダイアログを表示することができます。以前フォーカスされたウィンドウは、デフォルトでダイアログが閉じられた後にフォーカスが戻らない。以前に実行されていなかった場合、システムイベントとAppleScript Runnerの遅延が小さくなる可能性があります。

answer=$(osascript -e 'try 
tell application "SystemUIServer" 
set answer to text returned of (display dialog "" default answer "") 
end 
activate app (path to frontmost application as text) 
answer 
end' | tr '\r' '\n') 
[[ -z "$answer" ]] && exit 

フロントエンドアプリケーションにダイアログを表示するように指示することもできますが、それはしばしばやや遅くなります。アプリケーションが応答していない場合、ダイアログはすぐに表示されません。 MPlayer OS Xが最前面にある場合、テキストダイアログはキーボード入力を受け付けません。

answer=$(osascript -e 'try 
tell application (path to frontmost application as text) 
text returned of display dialog "" default answer "" 
end 
end' | tr '\r' '\n') 
[[ -z "$answer" ]] && exit