2011-05-09 132 views
0

我可以使用iCal創建新事件。爲什麼我不能使用變量來設置iCal事件?

tell application "iCal" 
    tell calendar "Todo" 
     set new_event to make new event at end of events 
     tell new_event 
      set start date to date "Friday, May 6, 2011 4:00:00 PM" 
      set end date to date "Friday, May 6, 2011 4:30:00 PM" 
      set summary to "Feed ferret" 
      set location to "Home 2" 
      set allday event to false 
      set status to confirmed 
     end tell 
    end tell 
end tell 

但是,當我使用一個變量來替換字符串時,我得到一個錯誤。

tell application "iCal" 
    tell calendar "Todo" 
     set new_event to make new event at end of events 
     set m_date to "Friday, May 6, 2011 4:00:00 PM" --> variable m_date 
     tell new_event 
      set start date to date m_date --> Error 
      set end date to date "Friday, May 6, 2011 4:30:00 PM" 
      set summary to "Feed ferret" 
      set location to "Home 2" 
      set allday event to false 
      set status to confirmed 
     end tell 
    end tell 
end tell 

enter image description here

爲什麼我不能使用變量設置iCal事件?

回答

1

因爲「日期」是該字符串轉換爲日期格式的功能iCal中接受這樣你就必須把「日期」在變量

on somefunction() 
    set m_date to date "Friday, May 6, 2011 4:00:00 PM" 
    my make_todo(m_date) 
end somefunction 

on make_todo(m_date) 
    tell application "iCal" 
     tell calendar "Todo" 
      set new_event to make new event at end of events 

      tell new_event 
       set start date to m_date 
       set end date to date "Friday, May 6, 2011 4:30:00 PM" 
       set summary to "Feed ferret" 
       set location to "Home 2" 
       set allday event to false 
       set status to confirmed 
      end tell 
     end tell 
    end tell 
end make_todo 

LL 端告訴

+0

感謝回答。實際上,我從文件中讀取時間信息並將其存儲到m_date中。使用日期函數,是否有辦法將變量用作數據函數的參數? – prosseek 2011-05-09 14:42:11

+0

@prosseek聽起來像一個單獨的問題,但是是的 – mcgrailm 2011-05-09 14:46:57

+0

我爲此發佈了另一個問題。謝謝。 - http://stackoverflow.com/questions/5938743/reading-ical-info-from-file-to-make-ical-event – prosseek 2011-05-09 15:03:27

相關問題