如何使用AppleScript在Outlook Mac中打开新的UNSAVED联系人?

时间:2013-02-18 15:34:14

标签: macos outlook applescript

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

1 个答案:

答案 0 :(得分: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编辑新联系人的字段,则必须首先保存该联系人。

第二次更新: 以下内容在创建联系人后放置在“tell application”系统事件“'块中时,将使用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