Thursday, August 25, 2011

Applescript for Apple Mail

Almost 6 months back I encountered a problem with desktop mail client on Mac. I had to use Applescript to solve the problem. I always wanted to copy whatever email I get onto my mac. I setup rules to copy certain emails based on specific criteria on my mac. The problem was whenever I read an email it was still unread on my mac. I tried every other method to make their status read. Nothing worked and so finally I opted for Applescript. You can see that the number of unread mail count on my mac is 716 while inbox has zero.

I wrote this applescript to solve this problem. Here it is:
tell application "Mail"
	set theMailboxes to every mailbox
	repeat with theMailbox in theMailboxes
		set theMessages to every message of theMailbox
		repeat with theMessage in theMessages
			if read status of theMessage is false then
				set read status of theMessage to true
			end if
		end repeat
	end repeat
end tell


It doesn't change the status of new emails in your inbox. It only changes the status of emails on your mac. Once you run the script in applescript editor you can see the count dropping down to zero very quickly.

The good thing with the script is you can make this run at specific times in a day by using ical. Just use alarm options in iCal to setup to run this script at certain of the day. I run this script at 8am early in the morning and at noon and at 4 pm, etc so that I don't see the annoying email count on my mac.

1 comment:

Anonymous said...

Sands Casino – San Jose - SEGA Online
Explore our newly 샌즈카지노 reopened slot machines and more at our new San Jose location in San Jose. It's time to relax and play the best slot machines in San Jose.

PBS Script Generator: Interdependent dropdown/select menus in Javascript

PBS SCRIPT GENERATOR
SH/BASH TCSH/CSH
Begin End Abort

About Me

LA, CA, United States
Here I write about the battles that have been going on in my mind. It's pretty much a scribble.

Sreedhar Manchu

Sreedhar Manchu
Higher Education: Not a simple life anymore