Sunday, April 20, 2014

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

dankj
Member
Registered: 2006-05-23
Posts: 5

Parse .csv files with applescript

Hello,
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 1.5.0.9
Operating System: Mac OS X (10.4)

Offline

 

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

julifos
Administrator
From: MalasaƱa, Madrid
Registered: 2002-11-20
Posts: 2014

Re: Parse .csv files with applescript

This can get you started:

Applescript:

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

Offline

 

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

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

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 <applescript-users@lists.apple.com> list and you'll get 40 or 50 hits in one thread discussing some of the difficulties.


iMac & MBP both running OS X 10.9.1

Offline

 

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

kel
Member
Registered: 2002-11-19
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.

gl,


Kel

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.026 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)