0

「OK」と「キャンセル」の 2 つのボタンがあるダイアログ ボックスがあります。「OK」ボタンで Web サイトを起動し、キャンセル ボタンでスクリプトを停止させたいと思います。現在、「OK」ボタンと「キャンセル」ボタンの両方で Web サイトが起動しています。何が欠けているのでしょうか?

osascript -e 'tell app "System Events" to display dialog "Things are broke \r \rPress OK to launch Google" buttons {"Cancel", "OK"}'
if [ "button returned:OK" ]; then 
    open "http://www.google.com"
else
    exit 0
fi
4

1 に答える 1

2

いくつかのオプションがあります。最初のほうが簡単かもしれません:

osascript -e 'tell app "System Events" to display dialog "Things are broke \r \rPress OK to launch Google" buttons {"Cancel", "OK"}' >/dev/null 2>&1
if [ $? -eq 0 ]; then open "http://www.google.com"; else exit 0; fi

osascriptまたは、次のような出力をキャプチャして解析します。

res=$(osascript -e 'tell app "System Events" to display dialog "Things are broke \r \rPress OK to launch Google" buttons {"Cancel", "OK"}' 2>/dev/null)

次に、次のように確認できます。

if [[ $res == *OK* ]]; then 
  echo OK
fi
于 2014-06-20T11:17:18.837 に答える