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

Show summaries of Mail's flagged emails on the Desktop Apps
[Note: This hint originally ran in mid-March, but was marked "must be logged in to read." As a result, it didn't go out in the RSS feed, and not many people saw it. I'm republishing it so that everyone has a chance to see it. -craig.]

I flag mail which I need to respond to, however, many times I forget to check my Flagged Mail mailbox. To keep these flagged mails visible, I finally sat down and -- with lots of help from the internet -- created the following AppleScript. With the help of Geektool, I now have the sender and subject of flagged mails visible on my desktop.

Here's the script:
set newline to ASCII character 10

set finalText to "Flagged Mail:" & newline
tell application "Mail"
  set theMessages to every message in inbox 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 finalText to finalText & "! " & word 1 of fromMsg & ": " & subjMsg & newline
  end repeat
end tell
finalText
Save this file as an AppleScript; I named mine flagged mail.scpt. In Geektool, add a Shell Geeklet with the following code:
osascript ~/Documents/Workflows/flagged\ mail.scpt
Hope this helps someone in the same situation as me.

[robg adds: This worked as described for me.]
    •    
  • Currently 2.79 / 5
  You rated: 4 / 5 (14 votes cast)
 
[8,650 views]  

Show summaries of Mail's flagged emails on the Desktop | 13 comments | Create New Account
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: metiure on Mar 22, '10 10:47:33AM

This is great, but it would be even greater if some Thunderbird user modified the original script



[ Reply to This | # ]
GeekTool monitors
Authored by: daeley on May 13, '10 08:05:40AM
Few years back, I used GeekTool and a script to create a combination mini Mail/NetNewsWire monitor and a iTunes status monitor. Here are the two posts:



[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: dwpoyner on May 13, '10 08:43:13AM

Is there a way to keep this script from opening Mail if it is not open but keep the script output consistent until Mail is opened and the script can run and update again?



[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: Sesquipedalian on May 13, '10 12:41:21PM
Sure. First change the command entered in GeekTool from

osascript ~/Documents/Workflows/flagged\ mail.scpt

to

osascript ~/Documents/Workflows/flagged\ mail.scpt > ~/Documents/Workflows/flagged\ mail\ output.txt; cat ~/Documents/Workflows/flagged\ mail\ output.txt.

Then add the following two lines to the top of the AppleScript code:

tell application "System Events"
if exists (application process "Mail") then

and the following lines to the end of the AppleScript code:

else
do shell script "cat ~/Documents/Workflows/flagged\ mail\ output.txt"
end if
end tell

Edited on May 13, '10 12:54:54PM by Sesquipedalian


[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: dwpoyner on May 13, '10 04:06:29PM

This doesn't keep it persistent. It rewrites over the file when Mail is closed. I understand what the script is trying to do, I just don't know how to fix it! Thanks!



[ Reply to This | # ]
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)
else
  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)
  else
    set finalText to "No Flagged Mail items cached. Open Mail to begin cacheing Flagged Mail"
  end if
  close access openTargetFile
end if

finalText

on WriteToFile(theData, targetFilePath)
  try
    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
    try
      close access the openTargetFile
    end try
    return false
  end try
end WriteToFile


[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: Sesquipedalian on May 15, '10 12:32:46PM
I fiddled some more, and produced this version. Instead of redirecting the output of the osascript command to a file, I now have osascript itself writing the file. Also, I've supplied all the AppleScript code as a series of direct arguments to osascript; this means that a separate .scpt file is unnecessary, in contrast to the original hint.

Just paste the following command into your Geeklet's command field:

outputfile=~/Documents/flagged\ mail\ list.txt; osascript -e "tell application \"System Events\"" -e "if exists (application process \"Mail\") then" -e "set newline to ASCII character 10" -e "set finalText to \"Flagged Mail:\" & newline" -e "tell application \"Mail\"" -e "set theMessages to every message in inbox whose flagged status is true" -e "repeat with i from 1 to number of items in theMessages" -e "set thisMessage to item i of theMessages" -e "set fromMsg to (sender of thisMessage as string)" -e "set subjMsg to (subject of thisMessage as string)" -e "set finalText to finalText & \"! \" & word 1 of fromMsg & \": \" & subjMsg & newline" -e "end repeat" -e "end tell" -e "set thefile to open for access posix file \"$outputfile\" write permission true" -e "set eof of thefile to 0" -e "write finalText to thefile starting at eof" -e "close access thefile" -e "end if" -e "end tell"; cat $outputfile

If you want, you can replace the ~/Documents/flagged\ mail\ list.txt bit at the beginning of the command with some other file path.

[ Reply to This | # ]

Show summaries of Mail's flagged emails on the Desktop
Authored by: dwpoyner on May 13, '10 03:20:13PM
Ok, so I worked with the script just a bit in order to keep it from opening Mail every time it wants to run. I also added in the received time of the message for reference. The data is not persistent though if Mail is not open. Maybe someone else can help me with that. I have no clue how to make that happen.

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


if MailIsRunning then
	
	set newline to ASCII character 10
	
	set finalText to "Flagged Mail:" & newline
	tell application "Mail"
		set theMessages to every message in inbox 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 timeMsg to (date received of thisMessage as string)
			set finalText to finalText & "! " & word 1 of fromMsg & ": " & subjMsg & "" & timeMsg & newline
		end repeat
	end tell
	
else
	return
end if
finalText


[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: matters on May 13, '10 02:01:55PM

This is awesome! I wish there was a way to make them links so you could click the email title to open it. :) That'd be awesomer.

Also, is there a way to make the text "Flagged email" at the top bold, but leave the rest normal?



[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: Fabricej on May 14, '10 07:28:13PM

@dushu: I've tried your script, and realized it can't work with my Imap Gmail account.
Can you post a new version of this script for imap users, please?
Thanx.



[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: echamings on May 17, '10 04:03:01AM

Would love to see this, gmail is my IMAP provider too.

Out of interest, what does it currently work with? Is it only non IMAP?



[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: Sesquipedalian on May 24, '10 08:24:18AM

Not sure what's wrong with your system, but I am a Gmail IMAP user, and it works fine for me.



[ Reply to This | # ]
Show summaries of Mail's flagged emails on the Desktop
Authored by: MichaelKo on May 01, '11 11:53:43PM

Nice. This was one of my options but I like this utility better: http://flaggedmailsapp.com/ . It displays the flagged mails in your menu bar instead.



[ Reply to This | # ]