"Not replied messages" script for Mail 2.0

I originally posted this message on the MacOSXhints forums http://forums.macosxhints.com/showthread.php?t=51935 and since one solution seems to use AppleScript, I thought posting the message on this forum would be appropriate and would perhaps find a more specialized audience. So, here’s again the problem I’m facing :

Thanks a lot for your help

Hi,

to get all messages of a mailbox which you have not replied to:

tell application "Mail"
	set noRepliedMails to (every message of mailbox "MyMailbox" whose was replied to is false)
end tell

D.

… but as far as I know, there is no way to connect this to an intelligent folder :frowning:

Maybe you could use a workaround like this:

Run a script app regularly with cron/launchd which marks all replied messages (and removes marks from all not replied messages)
Now you could use an ‘Intelligent Folder’ that shows only the marked messages.

D.

I agree with Dominik; that is probably the best way around this. I have also been frustrated with the lack of being able to script access to the Smart Folders in Mail, especially since they are just another folder in both iPhoto and iTunes. You can also get all your unread messages in all non-Smart folders thusly:

tell application "Mail"
	set a to every message in mailboxes whose was replied to is false
end tell

Good luck.

Hello, thanks for your help. I tried your script but when I run it from the Script Editor I get an error message “Mail got an error: NSReceiverEvaluationScriptError: 4” and then the line “every message of mailbox “mymailbox” whose was replied to is false” is higlighted. I tried to put names for other mailboxes but it doesn’t change anything. Also got an answer on my macosxhints post with a similar script (perhaps a bit more far down, you should check it) but I get exactly the same error message.

Sorry ef7,

my fault - stupid Mail understands the name of it’s mailboxes only as type 'Unicode text" - try this (works for me):


tell application "Mail"
	set allBoxes to (name of every mailbox)
	repeat with i from 1 to (count of allBoxes)
		set (item i of allBoxes) to (item i of allBoxes as text)
	end repeat
	set thisBox to (choose from list allBoxes) as Unicode text
	set noRepliedMails to (every message of mailbox thisBox whose was replied to is false)
end tell

D.

as for the script from osxhints:

it should work, if you add “as Unicode text” after the name arguments:


tell application "Mail"
   set mailitems to every message of mailbox ("everything" as Unicode text)
   repeat with i from 1 to count of mailitems
      set thismessage to item i of mailitems
      if was replied to of thismessage is false then
         move thismessage to mailbox ("notrepliedto" as Unicode text)
      end if
   end repeat
end tell

edit: this script is way too complicated - here is a shorter script:

tell application "Mail"
	move (every message of mailbox ("everything" as Unicode text) whose (was replied to is false)) to mailbox ("notrepliedto" as Unicode text)
end tell