Export from Mail to Numbers - Old Mac OS

Hi

With your help I’ve been able to us my script thank-you! But —
While I’m using the script fine but mac os 11.6.8 but my other user has an error running a much older os

  • Mac OS 10.10.5

Is there a fix?
Screenshot and script below. Thanks again.

set dataLst to {{"SenderNameAddr", "torecipientsNameAddr", "ccrecipientsNameAddr", "Subject", "Date", "Time", "Content"}}

tell application "Mail"
	repeat with aMsg in items of (get selection)
		tell aMsg
			set senderNameAddr to sender
			set torecipientsNameAddr to my flattenList(address of to recipients)
			set ccrecipientsNameAddr to my flattenList(address of cc recipients)
			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
			if (count msgContent) > 300 then set msgContent to rich text 1 thru 300 of msgContent
			set msgLst to {senderNameAddr, torecipientsNameAddr, ccrecipientsNameAddr, msgSubj, msgDate, msgTime, msgContent}
			copy msgLst to dataLst's end
		end tell
	end repeat
end tell

tell application "Numbers"
	set newDoc to make new document
	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)
		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 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

on flattenList(theList)
	set {saveTID, text item delimiters} to {text item delimiters, {", "}}
	set theString to theList as text
	set text item delimiters to saveTID
	return theString
end flattenList

The error says that either the older version of Numbers doesn’t know the table and sheet keywords or the class tokens NmTb and NmAS have been renamed.

In case of the former there is no fix, in case of the latter the script must be recompiled.

Hi.

Testing on my Sonoma machine, the problem seems to be that Numbers doesn’t allow the number of non-header rows (and presumably non-header columns) to be zero. If you set row count to 2, or delete the header row or set header row count to 0 first, the Numbers part of the script works.

Now I come to think of it, the active sheet property didn’t exist in older versions of Numbers. It was necessary to specify the required sheet either by name or by index. So while what I wrote above is true, StefanK’s explanation could more pertinent to the error message. Unfortunately I don’t remember when active sheet was introduced. I think it was around the time that Numbers and Pages had their AppleScript support dumbed down.

A workaround could be to refer to the sheet by name or index