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: 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 | # ]