Hi,
I’m just getting into applescript, and I could use your help. Most of what is below is something I found online, and it’s very close to doing what I want!
I would like to run an applescript that will extract parts of selected emails, and paste those parts to a Numbers sheet. The below code works to do that, but if I run it again, it overwrites my rows.
<<Please help me add the number of rows equal to the length of “dataLst” so that it will add rows.>>
I know this should be simple, but I can’t get it to do it no matter what I try!
Thanks in advance,
Seth
set dataLst to {{“SenderAddress”, “SenderName”, “Subject”, “Date”, “Time”, “Content”}}
tell application “Mail”
repeat with aMsg in items of (get selection)
tell aMsg
set senderNameAddr to my splitEmail(sender)
set senderAddr to item 2 of senderNameAddr
set senderName to item 1 of senderNameAddr
set msgSubj to subject
set msgDate to date received
set msgTime to time string of msgDate
set msgDate to my dateFormat(date string of msgDate)
set msgContent to content
set msgLst to {senderAddr, senderName, msgSubj, msgDate, msgTime, msgContent}
copy msgLst to dataLst’s end
end tell
end repeat
end tell
tell application “Numbers”
open “Macintosh HD:Users:xxxxxxxxx:desktop:Email_log.numbers”
tell table 1 of active sheet of newDoc
delete column “A” – remove default Header Column
set column count to length of item 1 of dataLst
set row count to (length of dataLst)
set foundBlank to true
if foundBlank then
repeat with i from 1 to length of dataLst
repeat with j from 1 to length of item 1 of dataLst
set value of cell j of row i to item j of item i of dataLst
end repeat
end repeat
end if
end tell
end tell
to dateFormat(aDateString) → yyyy-mm-dd
set {year:y, month:m, day:d} to date aDateString
tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & “-” & text 5 thru 6 & “-” & text 7 thru 8
end dateFormat
to splitEmail(nameAddress)
set text item delimiters to “<”
tell nameAddress
set theName to text item 1
set theAddress to text 1 thru -2 of text item 2
end tell
return {theName, theAddress}
end splitEmail