gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:26:56 25 4
gpt4 key购买 nike

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

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

为什么会出现这个错误?

最佳答案

您首先遇到两个问题,您需要在循环后添加最后一个事件,然后您试图在 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

结束重复

关于applescript - 从文件中读取 iCal 信息以制作 iCal 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5938743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com