首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从文件中读取iCal信息以生成iCal事件

从文件中读取iCal信息以生成iCal事件
EN

Stack Overflow用户
提问于 2011-05-09 23:02:42
回答 1查看 4.1K关注 0票数 2

我有一个包含iCal事件信息的文件(/test.txt)。

代码语言:javascript
复制
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事件。

代码语言:javascript
复制
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

运行这段代码会出现一个错误

为什么会出现这个错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-10 00:15:04

你有两个问题,首先你需要在循环之后添加最后一个事件,然后你试图在ical的tell块中设置日期,但由于某些原因无法工作,所以我把它从tell块中去掉了,我还对代码做了一些改进

代码语言:javascript
复制
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

结束重复

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5938743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档