Thanks, that did it.
Here is the whole thing, for those who (like myself) were having problems finding a resource on how to 1) read from a text file, and 2) how to create iCal records from Applescript. Some of this I found on the Net, and sorry, I don’t remember the source:
-- Schedule Event script
-- by Steven Weyhrich
-- A modification of a script posted on [url=http://www.blankreb.com/studiosnips.php?ID=17]http://www.blankreb.com/studiosnips.php?ID=17"[/url]
-- and the "Create a Birthday Calendar" script on Apple's web site
-- with help from kel on MacScripter.net
global theBigList, theFile
global theData, theLine
try
This part is necessary only in my particular situation, where I have a Word macro that sucks the pertinent date data off of a Word-based schedule. The macro creates a text file called “schedule…txt”, and stores it at a specific disk location.
The file contains records separated by returns, and within each record are two fields separated by tabs, a date followed by the name of the event:
10/11/04Daily meeting
10/12/04Power nap
etc.
--Run Schedule macro in Microsoft Word, to prepare the Schedule.txt file
display dialog "Be SURE that the AHFCC Schedule file is loaded into Microsoft Word and is the ONLY file that Word currently has open." as text
tell application "Microsoft Word"
do Visual Basic "Schedule"
end tell
Now, the important part.
tell application "iCal"
activate
set the calendar_name to "Steve Work" as string -- name of calendar where events are to be placed
if the calendar_name is "false" then error number -128
-- Read the tab-delimited file, putting the data
-- into a variable using a return as the delimiter.
-- This gives a list in which each item is
-- one line, or record, from the file
try
set theFile to alias "TiBookX:Users:steve:DL:schedule.txt"
set theData to read theFile as list using delimiter return
on error err_mess -- the file does not exist
display dialog err_mess
return
end try
set theData to read theFile as list using delimiter return
-- After declaring an empty list, fill it by changing AppleScript's
-- text item delimiters to tab and then creating a list called
-- theLine with the fields of each record as its items. Then
-- that list is copied to our empty list. The text item delimiters
-- are then set back to the default.
set theBigList to {}
set text item delimiters of AppleScript to tab
repeat with i from 1 to count of theData
set theLine to text items of item i of theData
copy theLine to the end of theBigList
end repeat
set text item delimiters of AppleScript to ""
-- Put up a barber pole dialog box in iCal that tells
-- what's going on.
show progress it with message "Adding events…"
delay 1
breathe now it
-- This is the loop that creates each event.
-- The date (item 1) is extracted from line i in
-- theBigList, and the event name is extracted
-- from item 2 of theBigList.
-- Since for my purposes, ALL of these events
-- start at 7am and end at 9am, the start and end
-- dates are created with that in mind.
repeat with i from 1 to count of theBigList
set eventSummary to item 2 of item i of theBigList as string
set event_date to item 1 of item i of theBigList as string
set e_start to event_date & " 07:00" as string
set e_end to event_date & " 09:00" as string
set eventStart to my get_date((e_start))
set eventEnd to my get_date((e_end))
set this_calendar to (the first calendar whose title is the calendar_name)
tell this_calendar
set this_event to make new event at end of events with properties {start date:eventStart, end date:eventEnd, summary:eventSummary}
(* for adding an alarm to the event
tell this_event
make new mail alarm at end of mail alarms with properties {trigger interval:-900}
end tell
*)
end tell
end repeat
show progress it with message "Importing completed."
delay 2
dismiss progress it
end tell
on error error_message number error_number
try
tell application "iCal"
dismiss progress it
end tell
end try
if the error_number is not -128 then
display dialog error_message buttons {"OK"} default button 1
end if
end try
on get_date(this_date)
return date this_date
end get_date
Again, many thanks for your help, kel!