让AppleScript发送电子邮件,然后通过shell脚本重新启动计算机?
我正在努力将我的 MBP 转换为媒体中心,如果计算机变得太热,我在其上设置的应用程序之一将运行一个脚本。如果发生这种情况,它会触发一个 AppleScript,它会向我发送一封电子邮件(告诉我发生了什么),然后重新启动计算机。
但问题是,重新启动不会等到邮件发送消息。我该如何补救?
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
另外,我使用 shell 脚本重新启动计算机的原因是因为我无法找到一种方法来在使用重新启动时关闭“您要保存...”对话框。
I'm working on converting my MBP into a media center, and one of the apps I have set up on it will run a script if the computer gets too hot. If this happened, it would trigger an AppleScript that would send me an email (telling me what happened) and then restart the computer.
The problem however is that the restart won't wait until Mail has sent the message. How can I remedy this?
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
Also, the reason why I am using a shell script to restart the computer is because I couldn't find a way to dismiss the "Do you want to save..." dialogs while using just restart.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查发送邮箱中邮件的循环属性“id”,如果存在则重新启动,或者如果 15 分钟内无法发送邮件则重新启动:
注意:我没有对这段代码进行太多测试,如果您愿意,请自行测试。
check in loop properties 'id' of your message in sent mailbox and reboot if it there or reboot if mail can't sent for 15 minutes:
note: I haven't tested this code much, please test it by yourself if you like.
潜水的答案对我不起作用,因为如果传出消息中没有“发送日期”属性,则无法将传出消息“id”与邮箱消息“id”或“消息 id”进行匹配。然而,对发送邮箱中的邮件数量进行计数是可行的:
当然这不应该在 linux 部分中?
dive's answer didn't work for me as there is no way to match an outgoing messages "id" with a mailbox messages "id" or "message id", are there is no "date sent" property in an outgoing mesage. However doing a count of the number of messages in the sent mailbox works:
and surely this should not be in the linux section?