1

我可以使用 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 字典中的任何内容看起来都没有希望。

4

1 回答 1

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

如评论中所述,需要启用“启用辅助设备访问”才能使其正常工作。这也可以通过 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
于 2013-03-13T01:18:41.710 回答