import csv into iCal

Is there any way to import a csv file into ical? You can import a csv into address book but not iCal. For example try putting this in your calendar. http://graphics.fansonly.com/schools/wash/graphics/csv/washfb_2009.csv

MacBook Pro 15", Mac OS X (10.6.1), 4GB mem

Posted on Oct 4, 2009 8:58 AM

Reply
5 replies

Oct 4, 2009 12:09 PM in response to snoho

You can use Applescript. Below is a sample that you can modify. Copy it into Script Editor and try it.


User uploaded fileAK

<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">--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 "iCal"
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</pre>

Oct 12, 2009 2:41 AM in response to Bcreags

The start and end of an event in iCal are stored in date format, thus carrying both date and time. These lines:

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)

use the date function to combine date and time data from the csv file into date-type variables which are then used in these lines

set newItem to make new event at end of events with properties {start date:StartDate}
set end date of newItem to EndDate

in setting up the new event in iCal.

I cannot recall why I did not include the end date with the properties, but maybe it was something I added afterwards.

User uploaded fileAK

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

import csv into iCal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.