2

動的 IP を .txt ファイルに自動的に書き込むスクリプトを使用していますが、終了ボタンをクリックしてもダイアログを閉じることができないという問題があります。

set yn to (display dialog "Your ip has been written to the server, the application will re-run in 10 minutes if you DO NOT close this window." buttons {"Quit", "Run again"} giving up after 600)
if yn is equal to "Quit" then
quit
end if
4

4 に答える 4

15

私が最終的にやったことは

display alert "This is an alert" buttons {"No", "Yes"}
if button returned of result = "No" then
     display alert "No was clicked"
else
    if button returned of result = "Yes" then
         display alert "Yes was clicked"
    end if
end if

「表示アラート「いいえ/はいがクリックされました」」という行を、実行したいコードに置き換えることができます

于 2013-03-03T17:26:54.013 に答える
6

ynのボタンが押されたことを利用する方法を理解する最も簡単な方法は、以下を見ることですyn:

set yn to (display dialog "Your ip has been written to the server, the application will re-run in 10 minutes if you DO NOT close this window." buttons {"Quit", "Run again"} giving up after 600)
return yn

ynが返されることがわかります{button returned:"Quit", gave up:false}。これは、ステートメントで使用できるynプロパティがあることを示します。button returnedif

display dialogこれを理解するもう 1 つの方法は、StandardAdditions ディクショナリであるAppleScript ディクショナリ ([ファイル] > [ディクショナリを開く...]) を参照することです。

于 2013-03-02T04:00:48.947 に答える
1

元の質問に回答として追加するにはgiving up after、ダイアログがタイムアウト期間を超えた場合にスクリプトで何かをする必要がありました。タイムアウトを考慮した追加オプションを次に示します。

set dialogTitle to "Star Wars Question"
set theDialog to display alert "Do you think Darh Maul should have his own movie?" buttons {"YES", "NO"} default button "YES" giving up after 10
if button returned of theDialog = "" then
    display notification "No decision was made, cancelled dialog" with title dialogTitle
else if button returned of theDialog = "YES" then
    display notification "I concur" with title dialogTitle
else if button returned of theDialog = "NO" then
    display notification "I find your lack of faith disturbing" with title dialogTitle
end if
于 2016-12-16T16:21:40.337 に答える