list - 使用 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
解决方案
根据上面的评论,我认为你想做这样的事情:
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 来测试这个,所以我不能肯定它会起作用。
推荐阅读
- drupal - Drupal Group 模块,以编程方式将用户添加到具有特定角色的组
- vue.js - 在 vue Bootstrap 数据表中添加事件
- php - 将相同的数组值相加到单个数组中
- javascript - NestJS如何在上传图片之前验证正文?
- javascript - 如何使用来自 API 响应的 JSON 呈现材料表?
- video - 视频是否预乘?
- c# - 将一些复选框绑定到组合框到 listView
- reactjs - 带有嵌套链接的 React Fabric UI Nav 始终可折叠
- excel - 合并多个 Worksheet_SelectionChange
- eclipse - 如何将语言设置条目添加到现有的 CDT eclipse 项目?