使用Mac OS X Automator解析iCal事件

时间:2015-10-25 07:47:04

标签: macos applescript automator osx-elcapitan

Here's the file I've created

The same file uploaded to different filestorage

我想要做的是从iCal事件摘要中获取公司名称和日期,并将它们放入Excel文件或本地变量中。摘要具有以下模式:

$_Compamy name 11.11.2011

示例:

$_ОАО "Газпром" 11.11.2011
$_Gazprom OJSC 11.11.2011

我的想法是过滤包含$_的条目,然后修剪最后10个字符(或从摘要中提取日期)。 问题在于自动机的事件摘要功能,它会生成太多奇怪的文本,如下所示:

TOTAL EVENTS: 3

EVENT 1 OF 3
Summary:    $_Gazprom OJSC 11.11.2011
Status: none
Date:   10/6/15 to 10/6/15
Time:   9:00:00 AM to 10:00:00 AM

我需要单独构建名单和日期列表,以便将它们用于文档填写,但我无法弄清楚如何获取日历中所有事件的特定文本。

1 个答案:

答案 0 :(得分:0)

如果您只想要一个摘要字符串列表,而不需要所有奇数文本,则需要使用AppleScript作为独立脚本,或者在Automator中的运行AppleScript 操作中使用。以下是一些通用代码,这些代码将在特定日历中创建一周特定日期摘要的列表,并在评论中添加一些解释:

--This section just defines a pair of dates to search within the Calendar
set rightNow to current date --Today
set rightNow's time to 0 --Set the time to the beginning of the day
set oneWeek to rightNow + (days * 7) --Add 7 days to get a week of Events

set eventSummaries to {} --Define an empty list to hold all of the Event Summaries
tell application "Calendar"
    set thisCalendar to item 1 of (get every calendar whose name is "Craig") -- Identify the Calendar to pull the Events from
    set theseEvents to every event of thisCalendar whose start date is greater than rightNow and start date is less than oneWeek -- Get the Events
    repeat with eachEvent in theseEvents
        set end of eventSummaries to eachEvent's summary -- Add each Event's Summary to the empty list
    end repeat
end tell
祝你好运,