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


Click here to return to the 'Scripts from Sal at Apple...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Scripts from Sal at Apple...
Authored by: robg on Jan 16, '04 12:38:03AM
Sal Soghoian, Apple's AppleScript guru, sent me the following email -- everything from here on is Sal's writing:

I noticed your scripts for controlling the display of messages in Mail. The fastest and easiest way is to use the power of AppleScript "whose" clauses:


try
  tell application "Mail"
    activate
    tell the front message viewer
      set the visible messages to every message whose ¬
      read status is false
    end tell
  end tell
on error error_message
  display dialog error_message("Cancel") default button 1
end try

try
  tell application "Mail"
    activate
    tell the front message viewer
      set the visible messages to every message whose ¬
      flagged status is true
    end tell
  end tell
on error error_message
  display dialog error_message("Cancel") default button 1
end try

try
  tell application "Mail"
    activate
    tell the front message viewer
      set the visible messages to every message
    end tell
  end tell
on error error_message
  display dialog error_message("Cancel") default button 1
end try
OK, it's robg again: I tested these, and they (not surprisingly!) worked as Sal described...

-rob.

[ Reply to This | # ]
Scripts from Sal at Apple...
Authored by: kmue on Jan 16, '04 03:05:51AM
Very sleek code! Unfortunately the error messag did not work (on Panther)

on error error_message
  display dialog error_message("Cancel") default button 1
though its possible to leave it out it would be nice to know how to correct this.

[ Reply to This | # ]
Scripts from Sal at Apple...
Authored by: eksimo on Jan 16, '04 07:34:33AM
this should work:

on error error_message
  display dialog error_message buttons {"Cancel"} default button 1
end try
although i would add some more feedback in the dialog, like

on error error_message
  beep
  display dialog "error showing flagged mails only: " & return & return & ¬
    error_message buttons {"OK"} default button 1
end try


[ Reply to This | # ]
Scripts from Sal at Apple...
Authored by: ether on Jan 20, '04 04:41:02PM
combining Sal's hint, the diagnosis of the single-message bug, and the original hint, produces the following, which seems to work with one or more unread messages, and preserve the speedup of Sal's hint. The obvious parallel changes work for the 'flagged' case.

try
	tell application "Mail"
		activate
		tell the front message viewer
			set unReadMsgs to every message whose read status is false
			set properties to {visible messages:unReadMsgs}
		end tell
	end tell
on error error_message
	beep
	display dialog "No unread messages: " & return & return & error_message buttons {"OK"} default button 1
end try


[ Reply to This | # ]
Scripts from Sal at Apple...
Authored by: aaronfreimark on Jan 16, '04 10:14:30AM
I rolled the scripts above into a toggle script. I named this file "Toggle Show Flagged___cmd-\.scpt", but you can name it what you like...
if ViewerIsFiltered() then
	try
		tell application "Mail"
			activate
			tell the front message viewer
				set the visible messages to every message
			end tell
		end tell
	on error error_message
		display dialog error_message {"Cancel"} default button 1
	end try
else
	try
		tell application "Mail"
			activate
			tell the front message viewer
				set the visible messages to every message whose ¬
					flagged status is true
			end tell
		end tell
	on error error_message
		display dialog error_message {"Cancel"} default button 1
	end try
end if

on ViewerIsFiltered()
	try
		tell application "Mail"
			activate
			tell the front message viewer
				set numThere to count of messages  ¬
					of the selected mailboxes
				set numShown to count of visible messages
			end tell
			
			if numShown = numThere then
				return false
			else
				return true
			end if
		end tell
	on error error_message
		display dialog error_message {"Cancel"} default button 1
	end try
end ViewerIsFiltered


[ Reply to This | # ]
Scripts from Sal at Apple...
Authored by: googoo on Jan 16, '04 12:57:09PM

I cannot get the first (read status false) script above to work! (Mac OS X 10.3.2) The error message I get is

NSUnknownKeyScriptError

The second and third scripts work flawlessly, though. I suspect the problem is with the read status property. Any ideas?

-Mark

[ Reply to This | # ]

Scripts from Sal at Apple...
Authored by: googoo on Jan 16, '04 12:58:42PM

BTW, I was referring to Sal's scripts above!

-Mark



[ Reply to This | # ]
a bug with "visible messages" ... it has to consist of at least 2 messages?
Authored by: eksimo on Jan 17, '04 12:42:26PM
maybe you have only 1 unread mail? there seems to be a bug with visible messages, as this list has to consist of at least 2 messages ... with only 1 or less you get that "NSUnknownKeyScriptError" error ... kind of buggy :-(

[ Reply to This | # ]
a bug with "visible messages" ... it has to consist of at least 2 messages?
Authored by: googoo on Jan 20, '04 11:07:38AM

That was it. Now why did I not think of that!

-Mark



[ Reply to This | # ]
a bug with "visible messages" - no, just bad AS coding...
Authored by: aamann on Apr 22, '04 02:04:52AM
It is not a bug with visible messages but rather an oversight in the coding of the original script...

Try using set the visible messages to every message whose read status is false as list which should work for single messages as well - AS automatically typecasts single item lists to non-list items...

[ Reply to This | # ]
Scripts from Sal at Apple...
Authored by: rsaum on May 15, '04 04:56:16PM

(I'm a complete novice). Script Editor wouldn't accept the syntax for any of the scripts in this thread, I post a screenshot here:
http://www.rsaum.co.uk/screenshot2.jpg
(similar syntax errors for any of the scripts). Chances are I'm missing something obvious, please enlighten . Also, I have the script menu in Finder but how do I get it in Mail?
Any help appreciated
Richard



[ Reply to This | # ]