用于使用邮件应用程序创建新邮件的Applescript
我有一个AppleScript for Mail.app,它会打开一个带有预定义收件人地址和主题的新邮件窗口。每次运行此脚本时,它都会打开一个新窗口:用于使用邮件应用程序创建新邮件的Applescript,applescript,Applescript,我有一个AppleScript for Mail.app,它会打开一个带有预定义收件人地址和主题的新邮件窗口。每次运行此脚本时,它都会打开一个新窗口: tell application "Mail" set newMessage to make new outgoing message with properties {subject:"some subject", content:"" & return & return} tell newMessage
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
但我希望脚本仅在先前打开的窗口关闭时才打开新的消息窗口,否则,先前打开的窗口应位于前面
有人能帮我修改这个脚本以实现上述功能吗 我没有测试这个,但它应该满足您的需要。。。至少它向你展示了正确的方法。您基本上使用“属性”来跟踪上次运行脚本时的一些值。在本例中,我们检查最前面窗口的名称,并查看它是否符合您的条件。如果窗口名不能满足您的需要,那么只需找到一些其他值,以便在脚本启动之间进行跟踪。基本方法应该有效 编辑:使用消息的唯一ID,执行以下操作:
property lastWindowID : missing value
tell application "Mail"
set windowIDs to id of windows
if windowIDs does not contain lastWindowID then
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
set lastWindowID to id of window 1
else
tell window id lastWindowID
set visible to false
set visible to true
end tell
activate
end if
end tell
可见性切换似乎是将窗口放在前面的唯一方法,因为最前面的
frontmost
是只读属性。只要脚本没有重新编译,lastWindowID属性就会存储该ID(注意:不要将其放入Automator服务中,因为每次加载服务时都会重新编译).谢谢您的建议。只有在其他邮件窗口未打开时,此操作才有效。如果其他窗口已打开,则为窗口1的名称返回的值将是错误的。正如我在回答中提到的,如果窗口名称不起作用,请使用其他属性。一个窗口有很多属性,所以你需要找到一些独特的东西。@regulus6633:实际上,window 1
将始终返回消息窗口,因为这是创建时的活动窗口–你的原始脚本创建了重复的新消息不是因为这个,而是因为它测试的第二个条件(window 1是lastWindowName
导致在窗口打开时创建一条新消息)。我编辑了它,切换到测试窗口id(唯一,与窗口名称不同),并添加了一个else
子句以将打开的窗口置于最前面。