Outlook 16.50下如何通过AppleScript获取日历重复系列单次事件的发生日期
问题原因
- Outlook AppleScript 的
selection接口针对重复日历事件返回的是「重复系列母版」对象,而非用户选中的单次实例,因此recurrence id始终返回missing value,start time也固定为系列首次会议的时间。
可行解决方法
利用日历视图的选中时间区间来获取单次实例的实际时间:用户选中单个重复会议实例时,日历视图的选中时间区间恰好对应该实例的实际开始/结束时间,不需要依赖事件本身的属性返回。
修正后的完整代码
tell application "Microsoft Outlook" activate if view of the first main window is equal to calendar view then set calendarEvent to selection -- 抓取选中的事件 -- 未选中事件时提示并退出 if calendarEvent is missing value then display dialog "请先选中一个日历事件后再运行此脚本!😀" with icon 1 return end if set eventTitle to subject of calendarEvent -- 抓取事件主题 set the_properties to properties of calendarEvent -- 修改部分:优先取视图选中的时间区间作为重复实例的实际时间 if is recurring of the_properties then tell calendar view of first main window set viewSelection to selection time set eventStart to start time of viewSelection end tell else set eventStart to start time of calendarEvent end if set startDate to date string of eventStart set startTime to time string of eventStart set docDay to second word of startDate set docMonth to third word of startDate set docYear to fourth word of startDate set docHour to first word of startTime set docMin to second word of startTime set monthList to {January, February, March, April, May, June, July, August, September, October, November, December} repeat with mth from 1 to 12 if docMonth = ((item mth of monthList) as string) then set tempMonth to (characters -2 thru -1 of ("0" & mth)) as string exit repeat end if end repeat set shortMonth to tempMonth set shortYear to (characters -2 thru -1 in docYear) as string set noteDateTime to docDay & "/" & shortMonth & "/" & shortYear & " " & docHour & ":" & docMin set theOrganizer to the organizer of calendarEvent set noteTitle to eventTitle & ", " & startDate set emailList to get every email address of every attendee of calendarEvent set nameList to "" set ind to 0 repeat with theName in emailList set ind to (ind + 1) set currentName to name of theName if currentName contains "," then -- 转换「姓, 名」格式为「名 姓」 set currentName to (second word of currentName & " " & first word of currentName) end if if ind = 1 then set nameList to nameList & " " & currentName else set nameList to nameList & ("\\par ") & " " & currentName end if end repeat else display dialog "当前不是日历视图!😀" with icon 1 return end if end tell
补充说明
- 修正代码新增了
selection time属性的调用,该属性可以直接返回日历视图中选中的时间区间,完全匹配你点选的重复会议实例的实际时间,不需要计算重复规则 - 额外修复了原代码中字符串拼接时的类型转换问题,避免运行时报错
内容的提问来源于stack exchange,提问作者SheriffofNotts
相关产品推荐
相关产品推荐

