I need to update the last column of a CSV file. The code I am using is
as follows:
set CSV to "Macintosh HD_1:sample apple
script:Experimental:Exp_Simple_Event_ical2.csv"
set afile to open for access CSV
copy afile to fileRefNum --fileRefNum will be used to read upto the
field after which data has to be appended.
set alllines to read afile using delimiter {return}
set a_variables to {}
repeat with aline in alllines
set oldtids to the text item delimiters
set the text item delimiters to {","}
set list_of_variables to every text item of aline
set the text item delimiters to oldtids
set summary_csv to item 1 of list_of_variables
set location_csv to item 2 of list_of_variables
set description_csv to item 3 of list_of_variables
--set starttime_csv to item 5 of list_of_variables
--set endtime_csv to item 6 of list_of_variables
set end of a_variables to {var1:summary_csv, var2:location_csv,
var3:description_csv}
end repeat
tell application "iCal"
activate
--Checking whether test calendar "NewCal" already exists
if calendar "NewCal" exists then
delete calendar "NewCal"
end if
--Creating a test calendar "NewCal"
make new calendar with properties {name:"NewCal",
description:"NewTestCal"}
--Creating a new event
tell calendar "NewCal"
set Event_Date to current date
make new event at end with properties {summary:summary_csv,
location:location_csv, description:description_csv, start
date:Event_Date + 200 * minutes, end date:Event_Date + 260 * minutes}
end tell
--set first_event to event 1 of calendar "NewCal"
set start_date to start date of event 1 of calendar "NewCal" as
string
set starttime_csv to items 24 thru 27 of start_date as string
end tell
UpdateStartTime(starttime_csv, fileRefNum)
on UpdateStartTime(starttime_csv, fileRefNum)
set accumulatedSize to 0
set numberOfFields to 4
set fieldDelimiter to ","
repeat with x from 1 to numberOfFields
set q to read fileRefNum until fieldDelimiter
set accumulatedSize to accumulatedSize + (length of q)
--display dialog accumulatedSize
end repeat
write starttime_csv to afile starting at accumulatedSize + 1
end UpdateStartTime
PROBLEM faced:
"End of file error" on statement 'set q to read fileRefNum until
fieldDelimiter'.
I am not able to understand what is going wrong here. Please help
bebug this.
Thanks,
SKT.


|