(* Use to extract statistics based on email headers, e.g. Sentry crash reports. How to use: 1) select all relevant emails in Apple Mail (e.g. search for some subject text in an email folder, like SAMI-KEYBOARDS-ANDROID, and then select all hits) 2) run the following command in bash: `osascript extract_email_subject_lines.applescript` This will return a list of strings in the following format: 24.8.2021; SAMI-KEYBOARDS-ANDROID-JZ - RuntimeException: Unable to start activity ComponentInfo{no.uit.giella.keyboards.Sami/com.android... 1.5.2021; SAMI-KEYBOARDS-ANDROID-H4 - IllegalStateException: Calls to setProgressAsync() must complete before a ListenableWorker signal... This can be further processed in bash as needed, of course. Beware that for many mail messages, the process will take some time - AppleScript is not the speediest language in the world, but it gives access to text from GUI applications that would otherwise be cumbersome. *) use AppleScript version "2.4" -- Yosemite (10.10) or later use scripting additions on ParseEmailMessages(theMsg) tell application "Mail" set subj to subject of theMsg set DateName to date received of theMsg end tell set Msg to {subj:subj, DateName:DateName} return Msg end ParseEmailMessages on list2string(theList, theDelimiter) -- First, we store in a variable the current delimiter to restore it later set theBackup to AppleScript's text item delimiters -- Set the new delimiter set AppleScript's text item delimiters to theDelimiter -- Perform the conversion set theString to theList as string -- Restore the original delimiter set AppleScript's text item delimiters to theBackup return theString end list2string on run tell application "Mail" set output to "" set headerinfo to {} set theMessages to selected messages of first message viewer set countmails to count of theMessages repeat with i from 1 to count of theMessages set theMsg to item i of theMessages set subj to subject of theMsg set DateName to date received of theMsg set DateString to short date string of DateName set mailinfo to {DateString, subj} tell me to set output to list2string(mailinfo, "; ") set the end of headerinfo to the contents of output end repeat tell me to set headertext to list2string(headerinfo, " ") return headertext end tell end run