如何使用 AppleScript 和 Numbers 从我的联系人组名称制作弹出菜单?

How do I make a Pop-Up Menu from my Contacts Group names, using AppleScript and Numbers?

请注意:该网站不允许我 post 这个问题,除非我格式不正确,即 "code" 的两个中间部分实际上不是代码。我已经尽力编辑它,修复它,如果格式不好,我深表歉意。

我找到并调整了两个脚本,分别 运行。这是我的第一个 AppleScript 项目,我希望得到帮助将它们组合在一起制作一个脚本。

我希望脚本 2 使用脚本 1 的结果。 例如将菜单项设置为(脚本 1 结果名称)

我在通讯录中创建了一个虚拟测试组。弹出式菜单只需要名称。稍后我会在另一个脚本中使用相应的电子邮件地址。

我希望这已经足够清楚了。预先感谢您的帮助。

脚本 1

--returns Contacts testGroup’s names and email addresses

set myList to ""
tell application "Contacts" to repeat with p in people in group "testGroup"
    if emails of p is {} then
        set e to ""
    else
        set e to value of email 1 of p
    end if
    set myList to myList & name of p
end repeat

脚本 1 结果需要解析...

"Joe BloggsMolly MousePeter Pan"

对此...

{"Joe Bloggs", "Molly Mouse", "Peter Pan"}

所以我可以在下面的脚本 2 菜单项中使用它。

脚本 2 必须使用脚本 1 结果中的名称,如下所示

-- Make Pop-Up Menu in Numbers spreadsheet which is already open.

set menuItems to {"Joe Bloggs", "Molly Mouse", "Peter Pan"}

tell application "Numbers"
    activate
    tell the first table of the active sheet of document 1
        tell cell "A3"
            set value to item 1 of menuItems
            set the format to pop up menu
        end tell
    end tell
end tell


tell application "System Events"
    tell application process "Numbers"
        set frontmost to true
        tell window 1
            click radio button "Cell" of radio group 1
            repeat with i from 2 to (count menuItems)
                click button 1 of group 1 of scroll area -1
                keystroke (item i of menuItems)
            end repeat
        end tell
    end tell
end tell

第一个脚本通过列表列表的项目来创建一个字符串,而第二个脚本只需要列表。由于联系人应用程序将为您提供姓名列表,因此根本不需要第一个脚本 - 第二个脚本的 menuItems 可以设置为:

tell application "Contacts" to set menuItems to the name of people in group "testGroup"