2013-07-04 88 views
0

我使用iCal來跟蹤我的班次,事件信息是相同的三個標準班次類型,我通常複製並粘貼它們,因爲沒有模式。Applescript創建設置iCal事件

我想解決如果使用AppleScript加速它們的情況。我想輸入一些日期和班次類型讓Applescript創建事件。

我想看看我是否能適應這個爲每個班次類型:

Reading iCal info from file to make iCal event

例如,所以我只是有日期的列表,但我甚至不能得到原始與跑得越來越無效的日期錯誤。

回答

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 
+0

非常棒 - 謝謝!我已通過添加:顯示對話框「輸入班次」默認答案「日/月班」 設置輸入(文本返回結果)有無論如何讓整個事情循環,所以我可以將其保存爲應用? – Rob

+0

實際上已經解決了......只好在正確的地方添加重複。 – Rob

2

這是一種方法。注意我在Mountain Lion上,所以應用程序是Calendar,而不是iCal ...但如果您使用的是iCal,則命令相同。您的日期錯誤很可能是因爲您的日期必須採用applescript日期格式。請注意,我將開始日期和結束日期以字符串格式初始化,並將它們轉換爲Apple日曆日期,然後再將事件添加到日曆。

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