Monday, March 19, 2018

#1 2006-12-30 01:56:20 pm

Registered: 2006-05-23
Posts: 5

Parse .csv files with applescript

What I am trying to do:
I am a college student and am somewhat new to applescript. My problem is that different profs give me important dates for their courses through different mediums such as: internet, excel, and on paper. It is easy for me to bring all the dates into an excel file and save it as .csv. I have around 150 of these dates that i need to put into entourage as calendar events. It would save me a great deal of time if i could write a script that would create calendar events from from the .csv file rather than manually creating 150 calendar events.

What i know:
I found some scripts that came with entourage that let me create a calendar event. So i can create a calendar event with applescript.

Where my problem right now is:
Right now i need to parse a .csv file which contains 3 values per line for example:

Jan 4, Topic 1: the cell, 8:30
Jan 8, Topic 2: microorganisms , 11:00
Jan 11,Topic 3: mitochondria , 9:30

I have no idea how to do this, any help would be greatly appreciated. (my system information is located below)

Model: MacBook Pro
AppleScript: 1.10.7
Browser: Firefox
Operating System: Mac OS X (10.4)



#2 2006-12-30 04:10:44 pm

From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

Re: Parse .csv files with applescript

This can get you started:


set csvData to "Jan 4, Topic 1: the cell, 8:30
Jan 8, Topic 2: microorganisms , 11:00
Jan 11,Topic 3: mitochondria , 9:30"

--> or:
-- set csvData to read file "path:to:file.csv"

set csvEntries to paragraphs of csvData

repeat with i from 1 to count csvEntries
   set {theDate, theTopic, theTime} to parseCsvEntry(csvEntries's item i)
   --> now, pass the parsed data to Entourage calendar event
   --> if you need a valid date, just:
   -- set fullDate to date (theDate & space & "2007" & space & theTime)
end repeat

to parseCsvEntry(csvEntry)
   set AppleScript's text item delimiters to ","
   set {theDate, theTopic, theTime} to csvEntry's text items
   set AppleScript's text item delimiters to {""}
   return {theDate, theTopic, theTime}
end parseCsvEntry



#3 2006-12-30 06:16:11 pm

Adam Bell
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4660

Re: Parse .csv files with applescript

jj's advice will get you started if the CSV file is very straight-forward but if it is just any CSV that follows the standard, it can be quite complex. Search on CSV in the Applescript Users <> list and you'll get 40 or 50 hits in one thread discussing some of the difficulties.

iMac running OS X 10.13.1



#4 2006-12-30 08:15:10 pm

Registered: 2002-11-20
Posts: 2031

Re: Parse .csv files with applescript

Hi dankj,

Also, you can learn to use Excel to import csv data. Within Excel, you can format the date field to date and time field to time. When you have everything done, you can create events in Entourage straight from the data.





Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)