首页 > 解决方案 > 使用 AppleScript 访问嵌套属性

问题描述

我有一个applescript,用于从Outlook 日历事件中提取几条信息,包括开始日期、标题和与会者。我遇到的问题是参加者课程。我只是想获取类的“名称”属性,但出现以下错误。从我所见,“名称”属性作为“参加者”类的“电子邮件地址”属性的一部分存在,因此它嵌套得很深。我想创建一个仅包含与会者姓名的列表。

这是错误

Can’t get item 1 of {name:"Attendee Name", address:"attendee@address.com", type:unresolved address}.

这是脚本。您必须先在 Outlook 中选择一个日历事件

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

global calendarTitle
global calendarDate
global calendarStart
global calendarAttendees
set show_note_in_new_window to true
tell application "Microsoft Outlook"
    activate
    delay 0.2
    set calendarEvent to selection
    -- if there are no tasks selected, warn the user and then quit
    if calendarEvent is {} then
        display dialog "Please select a calendar event first and then run this script." with icon 1
        return
    end if
    set calendarTitle to subject of calendarEvent
    set calDate to {month, day, year} of (current date)
    set calendarDate to calDate as text
    set calStart to start time of calendarEvent
    set calendarStart to calStart as text
    set calendarAttendees to get attendees of calendarEvent
    repeat with attendeeEmail in calendarAttendees
        set attendeeEmails to get email address of attendeeEmail
    end repeat
    repeat with attendeeName in attendeeEmails
        set attendeeEmailName to get name of attendeeName
    end repeat
    tell application "System Events"
        repeat with attendee in attendeeEmailName
            display dialog attendee
        end repeat
    end tell
end tell

标签: listoutlookapplescript

解决方案


根据上面的评论,我认为你想做这样的事情:

set calendarAttendees to get attendees of calendarEvent
set attendeeEmails to get email address of every calendarAttendees
set attendeeEmailNames to {}
repeat with thisEmail in attendeeEmails
    copy name of thisEmail to end of attendeeEmailNames
end repeat

第 2 行将每个与会者的电子邮件地址收集到列表中attendeeEmails,然后第 3 到 6 行从每条记录中提取姓名并将其存储在attendeeEmailNames. 您可能可以在一行(第 2 行)中完成所有操作,如下所示:

set attendeeEmailNames to name of every email address of calendarAttendees

但是我没有 Outlook 来测试这个,所以我不能肯定它会起作用。


推荐阅读