用于使用邮件应用程序创建新消息的 Applescript
我有一个用于 Mail.app 的 AppleScript,它会打开一个包含预定义收件人地址和主题的新消息窗口。每次运行此脚本时,都会打开一个新窗口:
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"some subject", content:"" & return & return}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:"some name", address:"some address"}
end tell
activate
end tell
但我希望脚本仅在先前打开的窗口关闭时才打开新的消息窗口 - 否则,先前打开的窗口应该出现在前面。
谁能帮我修改这个脚本以实现上述功能?
I have an AppleScript for Mail.app which opens a new message window with pre-defined recipient address and subject. This script opens a new window every time I run it:
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"some subject", content:"" & return & return}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:"some name", address:"some address"}
end tell
activate
end tell
But I want the script to open a new message window only when the previously opened window is closed – otherwise, the previously opened window should come to the front.
Can anyone please help me in modifying this script to achieve the above mentioned functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有对此进行测试,但它应该可以满足您的需要......至少它向您展示了正确的方法。您基本上使用“属性”来跟踪上次运行脚本时的某些值。在本例中,我们检查最前面窗口的名称,看看它是否符合您的条件。如果窗口名称不能满足您的需要,那么只需找到一些其他值来跟踪脚本的启动之间的情况即可。基本方法应该有效。
编辑:使用唯一的消息 ID,以下内容将执行您想要的操作:
可见性切换似乎是使窗口位于前面的唯一方法,因为
frontmost
是一个读取窗口唯一的财产。只要脚本不重新编译,lastWindowID 属性就会存储 ID(注意事项:不要将其放入 Automator 服务中,因为这些会被重新编译每次加载服务时)。I didn't test this but it should do what you need... at least it shows you the proper approach. You basically use a "property" to keep track of some value from the last time the script was run. In this case we check for the name of the frontmost window and see if it matches your criteria. If the window name doesn't do what you need then just find some other value to track between launches of the script. The basic approach should work.
EDIT: using the ID of the message, which is unique, the following will do what you want:
the visibility toggle seems to be the only way to get the window in front, as
frontmost
is a read-only property. The lastWindowID property will store the ID as long as the script is not re-compiled (caveat empteor: do not put this into an Automator service, as these get re-compiled every time the service is loaded).