csv - 将 CSV 文件导入 iCal

标签 csv applescript icalendar

我在Word文档表中找到了我的教学时间表和学期计划。我想知道是否有办法将这些数据导入 iCal。在 iCal 中创建事件比将这些表复制到 Excel 文件并从那里导入 iCal 花费的时间要长得多。

数据将是一日事件,即 House-Gala Friday 22/02/2013,其余数据将是 2 周或 3 周事件,即 3 周 - Gr.10 数学 - 主题:指数(这些事件将是一个为期 5 天的事件(周一至周五),重复三周。)

这是我从互联网上获得的脚本 - 但它给出的第一个错误是它无法将 .csv 文件文本转换为 Unicode 类型。

脚本后面的另一个问题是让这 5 天的事件重复 3 到 2 周。

任何帮助将不胜感激。这是我到目前为止所拥有的:

  --Convert CSV file to iCal events
  --Prompts for file, then processes
  --expects date,start time,end time,event name,xxxx,calendar name
  --eg 12/01/2006,20:30,22:00,Water Committee,,TestCal
  --change the various text item ns if data order in a file line is different
  --blank lines skipped
  --if other data present (eg location, notes ...) add a line in the tell calendar Calno loop
--to include it eg set location to text item 5 of ThisLine
set OldDelimiters to AppleScript's text item delimiters
set LF to ASCII character 10
set theFile to choose file with prompt "Select CSV calendar file"
set theLines to read theFile
set AppleScript's text item delimiters to {LF}
set theLines to paragraphs of theLines
set AppleScript's text item delimiters to {","}
repeat with ThisLine in theLines
    if (count of ThisLine) > 0 then --ignore blanks
        set StartDate to date (text item 1 of ThisLine & " " & text item 2 of ThisLine)
        set EndDate to date (text item 1 of ThisLine & " " & text item 3 of ThisLine)
        set CalName to word 1 of text item 6 of ThisLine
        tell application "Calendar"
            set CalList to title of every calendar
            if CalName is in CalList then
                repeat with CalNo from 1 to count of CalList
                    if CalName is item CalNo of CalList then exit repeat
                end repeat
            else
                set NewOne to make new calendar at end of calendars with properties {title:CalName}
                set CalNo to 1 + (count of CalList)
            end if
            tell calendar CalNo
                set newItem to make new event at end of events with properties {start date:StartDate}
                set summary of newItem to text item 4 of ThisLine
                set end date of newItem to EndDate
            end tell --calendar
        end tell --iCal
    end if
end repeat
set AppleScript's text item delimiters to OldDelimiters

好的,谢谢您的回复,这是我到目前为止所得到的,我无法使用 NumberCount 作为事件重复的计数来重复:

set text item delimiters to ";"
repeat with l in paragraphs of (read "/Users/pienaar0/Desktop/test.csv" as «class utf8»)
if contents of l is not "" then
    set sd to date (text item 1 of l & " ")
    set ed to date (text item 2 of l & " ")
    set NumberWeeks to (text item 4 of l & " ")
    set NumberCount to NumberWeeks - 1
    tell application "Calendar" to tell calendar "Test"
        make new event with properties {allday event:true, start date:sd, end date:ed, summary:text item 3 of l, recurrence:"FREQ=WEEKLY;COUNT=2 * NumberCount"}

    end tell
end if
 end repeat

最佳答案

set text item delimiters to ","
repeat with l in paragraphs of (read "/Users/username/Desktop/test.csv" as «class utf8»)
    if contents of l is not "" then
        set sd to date (text item 1 of l & " " & text item 2 of l)
        set ed to date (text item 1 of l & " " & text item 2 of l)
        tell application "Calendar" to tell calendar "Test"
            make new event with properties {start date:sd, end date:ed, summary:text item 4 of l}
        end tell
    end if
end repeat

测试.csv:

01/25/2013,10:30PM,11:00PM,test event
01/26/2013,00:00AM,01:00AM,test event2

关于csv - 将 CSV 文件导入 iCal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14527398/

相关文章:

python - 使用 Python 代替 AppleScript

php - 如何使用 PHP 动态发布 ical 文件以供 Google 日历读取?

c# - 为什么 GMail 无法识别代码发送的 session 请求?

python - CSV 写入文件困难

php - 如何从 WordPress 插件中的函数下载 CSV 文件?

c# - 为 SqlBulkCopy 中的某些列设置常量值

java - 如何在Java中格式化CSV的行和列

macos - AppleScript:将 "whose"与记录值一起使用不起作用

macos - 在Applescript中移动文件,出现错误: “Finder got an error: Handler can’ t handle objects of this class.”

c# - session 提醒 (.ICS) 电子邮件附件不考虑时区,即使指定了 UTC 时间