您可以通过编写 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