【问题标题】:How to open a new UNSAVED contact in Outlook Mac with AppleScript?如何使用 AppleScript 在 Outlook Mac 中打开新的未保存联系人?
【发布时间】:2013-02-03 02:11:45
【问题描述】:

我可以使用 AppleScript 创建一个新联系人并将其打开以在 Mac Outlook 2011 中显示:

tell application "Microsoft Outlook"
    set newContact to make new contact with properties {first name:"Fred", last name:"Flintstone"}
    open newContact
end tell

但此联系人已保存。有没有办法可以打开一个新的未保存 Outlook 联系人,填写属性,然后让用户决定是否保存?

我已经修改了“制作新窗口”,但我无法到达那里。我一直收到错误:

error "Microsoft Outlook got an error: AppleEvent handler failed." number -10000

我认为我需要以不同的方式解决这个问题,但 Outlook AppleScript 字典中的任何内容看起来都没有希望。

【问题讨论】:

    标签: macos outlook applescript


    【解决方案1】:

    您可以通过编写 UI 元素脚本来打开新联系人:

    tell application "System Events"
      click menu item "Contact" of menu 1 of menu item "New" of menu 1 of menu bar item "File" of menu bar 1 of application process "Outlook"
    end tell
    

    更新: 但需要注意的是,新联系人在添加到 Outlook 数据库之前不是 AppleScriptable 对象,即被保存。如果将这些行添加到上述脚本中,您可以看到:

    tell application "Microsoft Outlook"
      set contactWindow to item 1 of (windows whose index is 1)
      get object of contactWindow
    end tell
    

    contactWindow 的对象是缺失值。

    因此,如果您想使用 Outlook Applescript 字典 API 编辑新联系人的字段,则必须先保存该联系人。

    第二次更新: 以下内容在创建联系人后放置在“告诉应用程序“系统事件”块中时,将使用 UI 元素脚本设置该联系人的姓氏、名字和电子邮件地址:

    set lastName to "Einstein"
    set firstName to "Albert"
    set emailAddress to "a.einstein@relativity.com"
    
    set value of text field 1 of splitter group 1 of window 1 of application process "Outlook" to lastName
    set value of text field 2 of splitter group 1 of window 1 of application process "Outlook" to firstName
    set value of text field 6 of scroll area 1 of window 1 of application process "Outlook" to emailAddress
    

    如 cmets 中所述,需要启用“启用辅助设备访问”才能使其正常工作。这也可以通过 AppleScript 以编程方式完成:

    -- turn on UI automation - may throw a permissions dialog
    if UI elements enabled is false then
      set UI elements enabled to true
    end if
    

    【讨论】:

    • 啊,太好了。但是这些字段(例如名字,姓氏)可以填写吗?
    • @Nicholas - 请查看我刚刚对我的回答所做的编辑。我认为如果不先保存联系人,您可能无法执行此操作。或者,您可以使用 UI 元素脚本来编辑未保存联系人中的字段,但这通常很麻烦。您要修改哪些字段?
    • 我认为你是对的。我需要在许多字段中输入数据。我会四处寻找,看看这对我来说是否是一个可行的解决方案(尽管我认为我们非常清楚这两种解决方案的局限性)。
    • 对于任何尝试此操作的人,我必须转到系统偏好设置 > 辅助功能并选中“启用辅助设备的访问权限”以使其正常工作。
    • 您也可以通过以下方式以编程方式执行此操作:
      -- 打开 UI 自动化 - 可能会抛出一个权限对话框
      如果 UI 元素启用为假,则
      将启用的 UI 元素设置为true
      如果
      结束
    猜你喜欢
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多