2011-05-09 2 views
2

iCal 이벤트 정보가 들어있는 파일 (/test.txt)이 있습니다.iCal 이벤트를 만들기 위해 파일에서 iCal 정보 읽기

Friday, May 6, 2011 4:00:00 PM 
05/08/2011 11:20:00 PM 
summary 
location 

Friday, May 6, 2011 4:00:00 PM 
05/08/2011 11:20:00 PM 
summary 
location 

그리고이 파일은 iCal 이벤트를 만들기 위해이 파일을 읽는 데 사용됩니다.

set Names to paragraphs of (read ("/test.txt")) 
set my_list to {} 
set temp_list to {} 
repeat with nextLine in Names 
    if length of nextLine is greater than 0 then 
     set temp_list to temp_list & nextLine 
    else 
     copy temp_list to end of my_list 
     set temp_list to {} 
    end if 
end repeat 

repeat with e in my_list 
    set my_list to {} 
    tell application "iCal" 
     tell calendar "Todo" 
      set new_event to make new event at end of events 
      tell new_event 
       repeat with j from 1 to count e 
        set content to item j of e 
        if j is 1 then 
         set start date to date content --> Error 
        end if 
        if j is 2 then 
         set end date to date content 
        end if 
        if j is 3 then 
         set summary to content 
        end if 
        if j is 4 then 
         set location to content 
        end if 
       end repeat 
      end tell 
     end tell 
    end tell 
end repeat 

이 코드를 실행하면 나에게 오류

enter image description here

을 제공합니다 왜이 오류가 무엇입니까?

답변

3

두 가지 문제점이 있습니다. 루프를 한 후 마지막 이벤트를 추가해야합니다. ical tell 블록 내부의 날짜를 설정하려고했는데, 어떤 이유로 작동하지 않습니다. 그래서 tell 블록에서 빼 냈습니다. 또한 코드를 조금 개선

set theData to read ("path:to:test.txt" as alias) 
set ParaCount to count of paragraphs of theData 

set my_list to {} 
set temp_list to {} 

repeat with i from 1 to ParaCount 
    set thispara to paragraph i of theData 
    if thispara is equal to "" then 
     copy temp_list to end of my_list 
     set temp_list to {} 
    else 
     set temp_list to temp_list & thispara 
    end if 
end repeat 
copy temp_list to end of my_list -- copy the last one to the list 

repeat with aEvent in my_list 
    set {start_date, end_date, sum, loc} to aEvent 
    set start_date to date start_date 
    set end_date to date end_date 

      --reduced to single line 
    tell application "iCal" to make new event with properties {start date:start_date, end date:end_date, summary:sum, location:loc} at end of events of calendar "Todo" 
end repeat 

최종 반복

관련 문제