使用Applescript设置默认的Microsoft Outlook for Mac签名

时间:2012-04-10 13:12:16

标签: outlook applescript

我编写了一个脚本,用于从Active Directory中获取信息,并在Microsoft Outlook for Mac中创建新的签名。

我使用以下代码创建签名(我将保留其他代码,因为它不是真正相关):

tell application "Microsoft Outlook"

    make new signature with properties {name:strName, content:contentHTML, plain text content:"", include in random:false}

end tell

其中strName是我从其他地方获得的签名的名称,而contentHTML是我在其他地方构建的HTML中的实际签名。

将此签名添加到Microsoft Outlook工作正常,但我无法看到如何将我创建的签名设置为当前帐户的默认签名。我已经完成了很多根本没有帮助的研究,我也在字典中搜索过。

1 个答案:

答案 0 :(得分:3)

这可以使用AppleScript完成。 Outlook 2011词典中没有任何内容可以专门执行此操作,因此可以通过编写UI元素的脚本来完成,这无疑是相当笨拙的。

签名是基于每个帐户设置的,因此您需要为此脚本提供帐户名称以及要为该帐户设置的签名名称。

setDefaultSignature to "strName" for "Gmail"

on setDefaultSignature to mySignature for accountName
  tell application "Microsoft Outlook" to activate
  tell application "System Events"
    -- turn on UI automation - may throw a permissions dialog
    if UI elements enabled is false then set UI elements enabled to true

    click menu item "Preferences..." of menu 1 of menu bar item "Outlook" of menu bar 1 of application process "Outlook"
    click item 1 of (buttons of window "Outlook Preferences" of application process "Outlook" whose description is "Signatures")
    click button "Default Signatures..." of window "Signatures" of application process "Outlook"

    repeat with thisRow in rows of table 1 of scroll area 1 of sheet 1 of window "Signatures" of application process "Outlook"
      if value of text field of thisRow as string is accountName then
        click pop up button 1 of thisRow
        click menu item mySignature of menu 1 of pop up button 1 of thisRow
        click button "OK" of sheet 1 of window "Signatures" of application process "Outlook"
        click item 1 of (buttons of window "Signatures" of application process "Outlook" whose description is "close button")
        exit repeat
      end if
    end repeat
  end tell
end setDefaultSignature