0

我使用 iCal 跟踪我的班次,事件信息是相同的三种标准班次类型,我通常复制并粘贴它们,因为没有模式。

我正在尝试确定是否可以使用 Applescript 来加快速度。我想输入一些日期和班次类型让 Applescript 创建事件。

我试图看看是否可以针对每种班次类型进行调整:

从文件中读取 iCal 信息以制作 iCal 事件

例如,所以我只有一个日期列表,但我什至无法运行原始日期而不出现无效日期错误。

4

2 回答 2

2

这是一种方法。请注意,我在 Mountain Lion 上,所以该应用程序是日历,而不是 iCal……但如果您使用的是 iCal,则命令是相同的。您的日期错误很可能是因为您的日期必须采用 applescript 日期格式。请注意,我将开始日期和结束日期(最初为字符串格式)转换为 AppleScript 日期,然后再将事件添加到日历中。

set calendarName to "Home"
set theSummary to "Event Title"
set theDescrption to "The notes for the event"
set theLocation to "Karl's House"
set startDate to "July 4, 2013 6:30:00 PM"
set endDate to "July 5, 2013 1:00:00 AM"


set startDate to date startDate
set endDate to date endDate

tell application "Calendar"
    tell (first calendar whose name is calendarName)
        make new event at end of events with properties {summary:theSummary, start date:startDate, end date:endDate, description:theDescrption, location:theLocation}
    end tell
end tell
于 2013-07-04T15:04:30.810 回答
0

您可以使用类似的内容创建日期对象date "7/4/2013 6:00 PM",但可识别的格式取决于在系统偏好设置中选择的区域或日期格式。

set input to "7/4 night
7/5 day"

set y to year of (current date)
set text item delimiters to " "
repeat with l in paragraphs of input
    set d to text item 1 of l
    set type to text item 2 of l
    if type is "night" then
        set sd to date (d & "/" & y & " 5:00 PM")
        set ed to date (d & "/" & y & " 11:00 PM")
    else if type is "day" then
        set sd to date (d & "/" & y & " 9:00 AM")
        set ed to date (d & "/" & y & " 5:00 PM")
    end if
    tell application "Calendar" to tell calendar "test"
        make new event with properties {start date:sd, end date:ed, summary:"work"}
    end tell
end repeat
于 2013-07-04T14:58:03.627 回答