I’m new to applescript and I’ve a problem when trying to read a csv file with multiple lines.
The data is like this -
30/01/02 09:18,“Working from Home - Sky engineer came to fix locking up problem - re-terminated arial.Still have problem”
06/02/02 09:21,"Sky engineer came and replaced amstrad digibox with pace - job 16320512
Yvonne unable to turn Sky on - ran engineer on his mobile who told her to turn it off and back on - still unable to turn on."
etc
These are diary entries so quite a few have more than one line.
This script is OK with the first line in the csv file ( A single line) but then fails : -
error “Can’t get item 1 of {}.” number -1728 from item 1 of {}
I think it’s down to the “paragraphs” element of class string but I’m unable to find a way round the problem. Any help would be appreciated.
The script ---->
set csvData to read file “Macintosh HD:Users:cliveriches:Documents:Diary2002All.csv”
set csvEntries to paragraphs of csvData
set tNotebook to “Test”
repeat with i from 1 to count csvEntries
set {theDate, theText} to parseCsvEntry(csvEntries’s item i)
set aDate to date theDate
set textlen to count theText
if textlen is greater than 50 then
set theTitle to (characters 1 thru 50 of theText) as string
else
set theTitle to theText
end if
tell application "Evernote"
create note with text theText title theTitle created aDate notebook tNotebook
end tell
end repeat
to parseCsvEntry(csvEntry)
set AppleScript’s text item delimiters to “,”
set {theDate, theText} to csvEntry’s text items
set AppleScript’s text item delimiters to {“”}
return {theDate, theText}
end parseCsvEntry
Model: iMac
AppleScript: 2.1.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)