Need very, very simple scripts to sort mail

I can’t seem to find simple enough sample scripts. There is the one to print out ‘hello world’ but that’s not the kind of thing I’m trying to do. I would like to make simple scripts just to do simple menu commands. I would like, for example, to make script for Mail that sorts the mail by date, and another one to sort the mail by color. That’s it, nothing else, no checking some variable or moving e-mail addresses special folders or changing every mail that has the word sally to blue and moving it to a mailbox. Sorry, I’m new at this but I’ve searched and searched and everything I find seems to be some complicated task and I can’t figure out the syntax just to select a menu item.

Thanks,
~peter

Hi Peter,

You can script the user interface in Applescript, but most people find this somewhat limiting. Mail has the ability of doing this without clicking menu item 4 of menu 3…

In Mail the list of messages is controlled by the Message Viewer class and you can change the sort column property to many different options.

In Script Editor go to the File menu and select ‘Open Dictionary…’. From there open Mail’s scripting dictionary. Under the ‘Mail’ suite you should find the entry for the Message Viewer class. One of the (many) properties is sort column which can be set to ‘date received column’ and another is sorted ascending which is a boolean (true/false) .

So you can write something like:

tell application "Mail"
	activate -- so you can see the effect
	set sort column of front message viewer to date received column
	set sorted ascending of front message viewer to true
end tell

or:

tell application "Mail"
	activate -- so you can see the effect
	set sort column of front message viewer to message color
end tell

So, to my mind finding how to use the application’s scripting dictionary is a key element in learning applescript.

Best wishes

John M

Hi John,

Thanks for the help. Unfortunately neither of the scripts seem to work. Nothing happens at all when I run them. Sorry, I’m relatively new at this. Is there some way to debug and figure out why nothing is happening. I do know how to use scripts, I mean I have made other scripts work so it’s not something completely stupid like not knowing how to run them.

Thanks,
~peter

Hi Peter,

Does Mail launch and come to the front when you run the script?

John M

I always have Mail already open and running when I run the script, and I have the script in the Scripts/Applications/Mail/ folder.

~peter