Question

I am currently trying to customize an AppleScript that is reading the unread Mails in the Inbox. That basically works fine except the fact, that I can#T manage to get the date of the mails.

After about 2 hours of googling around I found out that the Variable I need should be receivedate or deliverydate, but when trying to use one of these I get an error like this:

"...receivedate of id... cannot be converted to Type reference..."

Someone's got an Idea, how I can convert this?

And this is my current code:

tell application "System Events"
    set processList to (name of every process)
end tell
if processList contains "Mail" then
tell application "Mail"
    if (unread count of inbox) > 0 then
        set messageList to (messages of inbox) whose read status is false
        set output to "Mails:" & return & return & ""
        repeat with itemNum from 1 to (unread count of inbox)
            set itemDate to (receivedate of item itemNum of messageList)
            set output to output & itemDate & " - " & (extract name from sender of item itemNum of messageList) & return & subject of item itemNum of messageList & return & return
        end repeat
    end if
end tell
else
set output to "ÄpplMäil isch aus..."
end if
Was it helpful?

Solution

The term you are looking for is date received

tell application "Mail" to if running then
    if (unread count of inbox) > 0 then
        set output to "Mails:" & return & return & ""
        repeat with thisMsg in (get messages of inbox whose read status is false)
            tell thisMsg to set output to output & (date received) & " - " & (extract name from sender) & return & subject & return & return
        end repeat
    end if
else
    set output to "ÄpplMäil isch aus..."
end if

A quicker way to get the help you need is the Applescript dictionarie of Mail. All commands, classes and properties of Mail are in this dictionary.

One way of opening this dictionary is to use the Open Dictionary item in the File menu of AppleScript Editor. When you use this item, you will get a listing of the available applications that have dictionaries. Choose Mail and click the Open button or use the Browse button to navigate to an unlisted application.

Another way to open a dictionary, is to make use of AppleScript Editor's Library window. It's located in the Window menu below the Result History and Event Log History menu items. The Library window shows a list of default applications whose dictionaries you can open with a double click.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top