2012-01-22 5 views
0

私は自分のMBPをメディアセンターに変換しようとしています。私が設定したアプリケーションの1つは、コンピュータが暑すぎるとスクリプトを実行します。これが起こった場合、AppleScriptを起動して電子メール(私に何が起こったか)を知らせてから、コンピュータを再起動します。AppleScriptで電子メールを送信してから、シェルスクリプトでコンピュータを再起動しますか?

ただし、Mailがメッセージを送信するまで、再起動は待機しません。どのように私はこれを改善することができますか?私はちょうど再起動し利用しながらダイアログを「あなたは...保存しますか」却下する方法を見つけることができなかったので、また

tell application "Mail" 
    set theNewMessage to make new outgoing message with properties {subject:"Media Center Alert", content:"Media Center has encountered a problem. It is now restarting. ", visible:false} 
    tell theNewMessage 
     make new to recipient at end of to recipients with properties {address:"myemail"} 
     send 
    end tell 
end tell 
tell application "Finder" 
    do shell script "reboot now" password "mypass" with administrator privileges 
end tell 

、私はコンピュータを再起動するシェルスクリプトを使用していた理由です。

+1

私があなただったら、 'tell application" Mail "ブロック内のすべてを' '考慮しているアプリケーションの応答' 'ブロックで囲みます。再起動に関しては、次のようにしてください: 'do shell script/sbin/shutdown -r now"管理者権限でパスワード "yourPass" ' – fireshadow52

+0

なぜあなたはそれらをパッケージに入れますか?そしてシェルスクリプトはリブートせずにシャットダウンしたように見えますか? – Charlie

+1

'examine'節は、AppleScriptがメールの処理を完了するのを待つようにAppleScriptに指示します。その行はコンピュータを再起動します。 – fireshadow52

答えて

0

チェック送られたメールボックス内のメッセージのループ特性を「ID」で、それならばそこに再起動するか、メールが15分間送信されないことができる場合に再起動:

tell application "Mail" 
    set my_id to id of theNewMessage 

    set startDate to current date 
    set rebootDate to (current date) + 15 * minutes 
    rebootDate + 15 * minutes 

    -- wait 15 minutes for Mail.app, then reboot if message cannot be sent 
    repeat while startDate is not equal to rebootDate 
     set last_msg to first message of sent mailbox 
     set last_msg_id to id of last_msg 

     if last_msg_id is equal to my_id then 
      -- reboot 
     end if 
     delay 15 
    end repeat 
end tell 

注:私はこのコードをテストしていませんあなたが好きならば、自分でテストしてください。

+0

完成したかどうかを確認してシェルスクリプトを実行する方法はありませんか?私はこれを本当にシンプルで簡単に保ち、再度電子メールを送ろうとしています。コンピュータの温度が過熱した場合に電子メールが送信されるので、再起動したいと思います。 – Charlie

+0

あなたのメッセージのために送信されたメールボックスをチェックすることができます。または、メッセージの 'date sent'プロパティをチェックすることができます。 安全のため15分ループを追加しました。 Mail.appがあなたにメッセージを送ることができず、あなたがそれを待つでしょうから、再起動しないでください。 – dive

0

ダイビングの答えが私のために働いていませんでした。発信メッセージ "id"とメールボックスメッセージ "id"または "message id"を一致させる方法がないため、送信中に "date sent"メサージュ。

tell application "Mail" 

    set numOutgoingMessages to 1 
    set secondsToWait to 10 

    set preSentCount to count messages in sent mailbox 
    set secondsPassed to 0 

    repeat while secondsPassed is less than secondsToWait 

     set curSentCount to count messages in sent mailbox 

     if curSentCount is greater than or equal to preSentCount + numOutgoingMessages then 
      set secondsPassed to secondsToWait + 1 
     end if 

     if secondsPassed is less than secondsToWait then 
      delay 1 
     end if 

     set secondsPassed to secondsPassed + 1 

    end repeat 

end tell 

と確かにこれはLinuxのセクションにすべきではない。しかし、送信されたメールボックス内のメッセージの数のカウント作品をやって?

関連する問題