AppleScript的与邮件应用程序中创建新邮件 [英] Applescript for creating New Message with Mail application

查看:314
本文介绍了AppleScript的与邮件应用程序中创建新邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AppleScript的Mail.app这将打开pre-定义收件人地址和主题的新邮件窗口。这个脚本会打开我每次运行它​​时一个新的窗口:

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

但我想脚本打开只有当previously打开的窗口被关闭一个新邮件窗口 - 否则,previously打开的窗口应该走到前面

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?

推荐答案

我没有测试这一点,但它应该做你所需要的......至少它表明你的正确方法。你基本上使用的财产来跟踪某个值从最后一次运行脚本。在这种情况下,我们检查最前面的窗口的名称,看它是否符合你的标准。如果窗口名称不会做你需要什么,然后随便找一些其他的价值剧本的发射之间进行跟踪。基本方法应该工作。

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.

编辑:使用的消息,这是唯一的ID,下面会做你想要什么:

using the ID of the message, which is unique, the following will do what you want:

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

能见度切换似乎让前面的窗口的唯一途径,因为最前面是一个只读属性。在 lastWindowID 的属性将存储ID只要脚本不重新编译(的警告empteor 的:不要把成的Automator服务这一点,因为这些获得重新编译每次的业务加载时间)。

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).

这篇关于AppleScript的与邮件应用程序中创建新邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆