1

我很难破解这个。我已将 ICS 文件读入 AppleScript,我需要对其进行解析。这是我的代码

set calURL to "https://url.to.ics"
set calenderData to do shell script "curl " & calURL

数据读得很好,但我需要解析它。我希望脚本为每个事件读取 BEGIN:VEVENT 和 END:VEVENT 之间的数据。我不确定如何做到这一点,但是使用 foreach 循环或其他什么?

这是一个包含我的考试的示例日历。

开始:VCALENDAR
版本:2.0
X-WR-CALNAME:Eksamener
X-WR-CALDESC:
X-苹果-日历-颜色:#CC2B23FF
开始:事件
UID:C96EF18C-5D17-4170-8C67-832B7F90B464
摘要:TK 1100 Eksamen
序列:0
地点:
DTSTART;值=日期:20111213
DTEND;值=日期:20111214
结束:事件
开始:事件
UID:BDBE0B4B-FF3D-4245-B23F-F1BF25F65998
摘要:DB 1100 Eksamen
序列:0
地点:
DTSTART;值=日期:20111006
DTEND;值=日期:20111007
结束:事件
开始:事件
UID:21261AF0-FDA7-432B-B513-CC3A9C04393D
摘要:PG 1100 Eksamen
序列:0
地点:
DTSTART;值=日期:20111216
DTEND;值=日期:20111217
结束:事件
结束:VCALENDAR

这与学校无关,我只是想解析数据以在我的桌面(GeekTool)上查看。

4

1 回答 1

0

You need to use text item delimiters. Try this and see if you can understand how it works.

set theData to "BEGIN:VCALENDAR
VERSION:2.0
X-WR-CALNAME:Eksamener
X-WR-CALDESC:
X-APPLE-CALENDAR-COLOR:#CC2B23FF
BEGIN:VEVENT
UID:C96EF18C-5D17-4170-8C67-832B7F90B464
SUMMARY:TK 1100 Eksamen
SEQUENCE:0
LOCATION:
DTSTART;VALUE=DATE:20111213
DTEND;VALUE=DATE:20111214
END:VEVENT
BEGIN:VEVENT
UID:BDBE0B4B-FF3D-4245-B23F-F1BF25F65998
SUMMARY:DB 1100 Eksamen
SEQUENCE:0
LOCATION:
DTSTART;VALUE=DATE:20111006
DTEND;VALUE=DATE:20111007
END:VEVENT
BEGIN:VEVENT
UID:21261AF0-FDA7-432B-B513-CC3A9C04393D
SUMMARY:PG 1100 Eksamen
SEQUENCE:0
LOCATION:
DTSTART;VALUE=DATE:20111216
DTEND;VALUE=DATE:20111217
END:VEVENT
END:VCALENDAR"

set text item delimiters to "BEGIN:VEVENT"
set theEvents to text items of theData
set text item delimiters to "END:VEVENT"

set allEvents to {}
repeat with i from 2 to count of theEvents
    set theEvent to item i of theEvents
    set trimmedEvent to text item 1 of theEvent
    set end of allEvents to text 2 thru -2 of trimmedEvent -- you can do something here instead of collecting them in the list
end repeat
set text item delimiters to ""
return allEvents
于 2011-11-07T17:26:15.607 回答