Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

applescript: extract date received of mail

dear all,

I am searching for a routine which extracts the date of a specific, selected mail.

Thank you for any hint.


Something like this:

set junkCount to "0"

tell application "System Events" to set MailIsRunning to (name of processes) contains "Mail"

if MailIsRunning then

tell application "Mail"

set thisDate to the date string of the (date received)

display dialog "thisDate is " & thisDate

end tell

return junkCount

end if

MacBook Pro, iOS 5.1.1

Posted on Dec 31, 2014 12:38 AM

Reply
Question marked as Best reply

Posted on Jan 2, 2015 8:12 AM

Hi,



Try this script :


set dateList to {}
tell application "Mail" to if running then
    repeat with tMsg in (get selection)
        set end of dateList to the (date received of tMsg) as rich text
    end repeat
    return dateList
end if
4 replies

Feb 2, 2016 7:10 AM in response to rubinje

Hey rubinje, I'm an Applescript newbie and I was wondering if you ever got the date fixed?


I'm trying to recursively print 25,000 old, archived messages to PDF with a naming convention of:


YYYY-MM-DD - Subject


Since I had exported and backed these up I'm trying to open each individually in Mail and do this so I don't flood my Mail.app with too many old messages.



If you get this, let me know whether or not you were successful.

Feb 2, 2016 8:29 AM in response to OnceThereNowGone

This is what I was able to put together in the past ~hour, it might not be the simplest code (more of a beginner's brute forcing) but let me know what you think:


-- Gets the date of the selected message
-- https://discussions.apple.com/thread/6751836?start=0&tstart=0
-- This returns the date as "Day_of_the_Week, Full_Month Day, Year at Time AM/PM"
-- Date Conversion added by RSH - 2016-02-02

set dateList to {}
tell application "Mail" to if running then
  repeat with tMsg in (get selection)
  set end of dateList to the (date received of tMsg) as rich text
  end repeat
  set monthList to {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
  set numberList to {"1", "2", "3", "4", "5", "6", "7", "8", "9"}

-- Separating Email Date for Reordering
  set dateString to item 1 of dateList
  set emailYear to word 4 of dateString
  set emailMonth to word 2 of dateString
  set emailDay to word 3 of dateString as string
  set emailTimeHours to word 6 of dateString
  set emailTimeMinutes to word 7 of dateString
  set emailTimeSeconds to word 8 of dateString
  set emailAMPM to word 9 of dateString

-- Getting month value, added "as string" to fix single numbers to double digit (1->01)
  repeat with i from 1 to the count of monthList
  if item i of monthList is emailMonth then set monthPosition to i as string
  end repeat

-- Concatenating "0" onto single digit numbers to make them double
  if numberList contains monthPosition then set monthPosition to "0" & monthPosition
  if numberList contains emailDay then set emailDay to "0" & emailDay


-- Creating Reordered Date with Month Name
-- set orderedDateString to emailYear & "-" & emailMonth & "-" & emailDay & " " & emailTimeHours & ":" & emailTimeMinutes & ":" & emailTimeSeconds & " " & emailAMPM

-- Creating Reordered Date with Month Value
  set orderedDateString to emailYear & "-" & monthPosition & "-" & emailDay & " " & emailTimeHours & ":" & emailTimeMinutes & ":" & emailTimeSeconds & " " & emailAMPM

  return orderedDateString
end if

applescript: extract date received of mail

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.