Import txt or csv to iCal

Hi all,

I am trying to import a txt file for my favorite sports team but can't. Is this not possible to map this and import? I can convert the txt to csv or is there a utility to convert txt to ics? or csv to ics?

thx..ron

iMac, Mac OS X (10.4.8)

Posted on Dec 10, 2006 9:16 AM

Reply
16 replies

Dec 10, 2006 3:54 PM in response to RonsMac

This script worked for someone else. Paste it into a script editor window, read through it, ask any questions, modify the script and/or your file as needed, backup your calendars and then run the script.

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 text items 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>

Jan 10, 2007 8:42 PM in response to Austin Kinsella1

Austin,

I gave this script a whirl, and it seems to work, but it only imports the first line of my CVS file. Any idea why?

I'm no script writer...but it seems that this bit here isn't getting looped:

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

Any thoughts? Thanks!

Mar 5, 2007 7:57 AM in response to jfort

OK. I put the script in this thread plus the addition at the end, but it won't accept the .csv file I downloaded from the Indians web site. I have a txt/tab delineated version, too, and I deleted the first line with the column titles, but the script still says there is an error. any suggestions? It shouldn't be so difficult to be a Mac and iCal user.

Mar 5, 2007 11:34 AM in response to Austin Kinsella1

1) The script is expecting lines ending with a line feed (ASCII character 10). Your lines end with return (ASCII character 13).
Change line

set AppleScript's text item delimiters to {LF}


to

set AppleScript's text item delimiters to return



2) The script is expecting comma-separated values (that's what the CSV stands for). Your file uses tabs.
Change line

set AppleScript's text item delimiters to {","}


to

set AppleScript's text item delimiters to tab



3) The script is expecting the name of the calendar as the 6th data item on each line. Your lines have only 5 data items.
Change line

set CalName to word 1 of text item 6 of ThisLine


to

set CalName to word 1 of text item 5 of ThisLine


This will put the data into a calendar called "Indians". If you want to preserve the 2007, make that line instead

set CalName to text item 5 of ThisLine



I think that should cure it, but can't test it fully as your dates are the wrong way round (from my perspective 🙂. I ran it satisfactorily with the first 12 lines.

User uploaded fileAK

Mar 5, 2007 12:04 PM in response to Austin Kinsella1

I made changes thus and get error that script doesnt recognize starttime. Starttimes in spreadsheet have been formated so that 1pm is 13:00:

--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 13
set theFile to choose file with prompt "Select CSV calendar file"
set theLines to read theFile
set AppleScript's text item delimiters to return
set theLines to text items of theLines
set AppleScript's text item delimiters to tab
repeat with ThisLine in theLines
if (count of ThisLine) > 0 then --ignore blanks
set StartDate to date (text item 1 of ThisLine & " " & text item 1 of ThisLine)
set StartTime to StartTime(text item 2 of ThisLine & " " & text item 2 of ThisLine)
set EndTime to EndTime(text item 3 of ThisLine & " " & text item 3 of ThisLine)
set EventName to EventName(text item 4 of ThisLine & " " & text item 4 of ThisLine)
set CalName to text item 5 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 1 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
theLines

Mar 6, 2007 9:35 AM in response to jfort

I finally solved the problem with the help of two people from the UK. Austin Kinsella tweeked the script posted on this thread and was able to convert the data in an Excel spreatsheet and have it import into iCal. Then Mike Hay set up his program to convert the csv file. I kept getting an error message. He even emailed me the isc file result. Of course I made a donation. His program, iCalTextimport, is found at:

http://homepage.mac.com/penicuik/FileSharing15.html

I still think this is way too much trouble. iCal should have a better import function.

Aug 15, 2007 2:13 AM in response to RonsMac

YES! SUCCESS!

I found two ways of doing this. After searching the net, I found this online app on this guys website that worked the best:
http://manas.tungare.name/projects/yahoo2ical/

It says it's a "yahoo" csv converter, but it worked fine for my outlook csv file.



The other option is, if you have an account with google, like a gmail account, you can use their google calendar to import your csv file. Once you've done that, you can subscribe to that calendar you imported via the "share" option. Just get the .ics address. This took a couple tries on google's site to import, but it worked.

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 txt or csv to iCal

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