【问题标题】:Show a contact in Applescript在 Applescript 中显示联系人
【发布时间】:2014-08-26 01:42:42
【问题描述】:

我想知道如何在 Applescript 中显示联系人。基本上,我需要打开联系人,然后打开我想要的联系人。我不知道联系人的语法。

基本上,我只有

tell application "Contacts"
activate
end tell

所以,是的。基本上没什么哈哈。我也试过了:

tell application "Contacts"
set theContact to "Jason Wells"
open person theContact
end tell

但是,那没有用。

感谢任何帮助。

谢谢。

【问题讨论】:

    标签: macos applescript contacts


    【解决方案1】:

    Contacts 有点奇怪——至少在我的情况下,它似乎有一点错误。

    如果联系人是打开的,它会显示它的窗口;如果您关闭窗口,它会关闭应用程序。这意味着只要你选择了你想要的人,那个人就会显示出来。

    所以这应该会让你继续前进:

    --AppleScript seems to need Address Book as the application name
    --it will rename it to Contacts on save or compile.
    tell application "Address Book"
        activate
        set theContact to the first person whose name is "Jerold Stratton"
        --first group appears to be "card".
        set theGroup to second item of groups of theContact
    
        --first, move to a group that contains this contact
        set selected of theGroup to true
    
        --second, select the contact
        set selection to theContact
    end tell
    

    现在,在我的例子中,有一个错误:应用程序名为 Contacts,但 AppleScript 找不到它名为 Contacts。它会发现它名为“地址簿”。然后它将其重命名为联系人,这意味着下次您在联系人关闭时编辑脚本时,它将无法找到应用程序或其术语,直到您将其从联系人编辑回地址簿。这是在 OS X 10.9.4 上。

    【讨论】:

      【解决方案2】:

      感谢 Jerry Stratton 在此页面上的帖子,我能够将其分解为一行代码:

      tell application "Contacts" to set selection to person "Firstname Lastname"
      

      【讨论】:

        【解决方案3】:

        打开联系人字典,看到联系人卡片是一个“人”对象。你可以看到一个人的所有属性:

        tell app "Contacts" to get properties of person 1
        

        要找到您要找的人,您可以执行以下操作:

        tell application "Contacts" to set p to first person whose (first name is "Jason" and last name is "Wells")
        

        【讨论】:

        • 谢谢,这个答案也很有帮助。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多