Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Show summaries of Mail's flagged emails on the Desktop ' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Show summaries of Mail's flagged emails on the Desktop
Authored by: edljedi on May 24, '10 01:17:08AM
This is what I ended up with for persistance of the flagged items being displayed as well as going through more than just the inbox:
set newline to ASCII character 10

set pathApplicationSupport to (path to application support from user domain as text)
set fileSavedFlagged to pathApplicationSupport & "Mail:Flagged Mail.txt"

tell application "System Events" to set MailIsRunning to (count of (every process whose name is "Mail")) > 0

if MailIsRunning then
  tell application "Mail"
    set localMailboxes to every mailbox
    set finalText to "Flagged Mail:" & newline
    if (count of localMailboxes) is greater than 0 then
      repeat with eachMailbox in localMailboxes
        set theMessages to (every message in eachMailbox whose flagged status is true)
        repeat with i from 1 to number of items in theMessages
          set thisMessage to item i of theMessages
          set fromMsg to (sender of thisMessage as string)
          set subjMsg to (subject of thisMessage as string)
          set dateRcvdMsg to (date received of thisMessage as date)
          copy dateRcvdMsg to monthMsg
          set the month of monthMsg to January
          set monthNum to (1 + (dateRcvdMsg - monthMsg + 1314864) div 2629728)
          set dateRcvdMsg to (monthNum) & "/" & (day of dateRcvdMsg) & "/" & (year of dateRcvdMsg) & " " & (time string of dateRcvdMsg)
          set finalText to finalText & "> " & dateRcvdMsg & " - " & word 1 of fromMsg & ": " & subjMsg & newline
        end repeat
      end repeat
    end if
  end tell
  WriteToFile(finalText, fileSavedFlagged)
  set fileSavedFlagged to the fileSavedFlagged as Unicode text
  set openTargetFile to (open for access the fileSavedFlagged)
  set sizefileSavedFlagged to (get eof of the openTargetFile)
  if sizefileSavedFlagged > 0 then
    set finalText to "(Cached) " & (read openTargetFile)
    set finalText to "No Flagged Mail items cached. Open Mail to begin cacheing Flagged Mail"
  end if
  close access openTargetFile
end if


on WriteToFile(theData, targetFilePath)
    set targetFilePath to the targetFilePath as Unicode text
    set openTargetFile to (open for access the targetFilePath with write permission)
    write theData to the openTargetFile starting at 0
    close access the openTargetFile
    return true
  on error
      close access the openTargetFile
    end try
    return false
  end try
end WriteToFile

[ Reply to This | # ]