-- AppleScript to read the subject and date from all messages in a given Apple Mail mailbox. -- The results are appended to a Comma Separated Values (CSV) file. -- Written by Mark Wainwright of www.sallonoroff.co.uk -- Except "writeTo" file-writing function by regulus6633 on http://macscripter.net/viewtopic.php?id=36861 tell application "Mail" set theMailbox to mailbox "testing" -- CHANGE THIS VALUE TO ALTER THE TARGET MAILBOX set messageCount to count of messages in theMailbox -- Find out how many emails there are end tell set filePath to (path to desktop as text) & "output.csv" -- SETS OUTPUT LOCATION AND FILE NAME repeat with counter from 1 to messageCount -- Loop through all the emails tell application "Mail" set theMessage to message counter of theMailbox -- Pick the next email set msgSubject to subject of theMessage -- Gets the email subject set tempDate to date received of theMessage -- Gets the date and time set msgDate to date string of tempDate -- Strips the time bit from it end tell set theString to "Message " & counter & " of " & messageCount & "," & msgSubject & "," & msgDate & return -- Builds a line of the information we want set theResult to writeTo(filePath, theString, text, true) -- Save the line to file if not theResult then display dialog "There was an error writing data!" end repeat on writeTo(targetFile, theData, dataType, apendData) -- targetFile is the path to the file you want to write. -- theData is the data you want in the file. -- dataType is the data type of theData and it can be text, list, record etc. -- apendData is true to append theData to the end of the current contents of the file or false to overwrite it. try set targetFile to targetFile as text set openFile to open for access file targetFile with write permission if apendData is false then set eof of openFile to 0 write theData to openFile starting at eof as dataType close access openFile return true on error try close access file targetFile end try return false end try end writeTo