Apple Mail Help Please! Script and instructions needed..

Hello all,

I’m brand new to the forum and I was hoping for some help with a “script”. I’m very green with all this so excuse me in advance for lack of knowledge with the scripting process.

So my company is making the move to Apple and will start using the latest Mail application with the latest Yosemite OS. I like Mail but there is key feature I need and everybody I have spoken to says I need a “script” in Apple Script Editor to make this work. I need to launch mail and have all Unread Emails in the general Inbox be a different color. Right now, you only get the little blue dot. I would like the unread to be lit up orange or red. I cant have it be a smart mailbox as it needs to be in the general mailbox.

Any help would be much appreciated guys! It’s a must have here.
Again, I’m so sorry about my level of Apple Script. I have never worked with it before…

Would somebody mind posting detailed step by step instructions for me?

For Example “Open Apple Script Editor” Hit this button! hahaha.

Thanks again everybody! So far a member has been very helpful and told me to post the question to the group.

-Blake

Hi Blake,

welcome to MacScripter

This line sets the background color of all unread messages of the mailbox inbox to red.

tell application "Mail" to set background color of (messages of inbox whose read status is false) to red

Just click on “Open this Scriplet in your Editor” and run the script (⌘R).

Supported colors are blue, gray, green, none, orange, purple, red and yellow

Stefan,

Thanks again for your help with the Apple mail Script!! It worked perfect changing the unread to Red. However, after opening it and reading an unread, the color remains red. Is there another script you can provide me that will change the color back to white after I have read the email? Please provide that link you sent last time which was very easy for me to follow.

Thanks again for taking the time to help me! Much appreciated!

-Blake

You may try :

tell application "Mail" to set background color of (messages of inbox whose read status is false) to none

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) vendredi 28 août 2015 11:31:22

Isn’t this just the opposite? After running Stefan’s script, wouldn’t your script just mark everything with no background color just like it is by default from mail?

Right now I have Stefan’s script and it works perfectly with a red background on unread emails. But once I open the email, the email remains red. I need it to go back to the defaulted “white” background AFTER the email has been read.

Next question, do I run the script on the same script as Stefan’s or does it become a separate new Script?

Sorry, very green with this stuff!

Much appreciated guys!

-Blake

There is no way to change the color of a message automatically when opening it.

Either you run the script

tell application "Mail" to set background color of (messages of inbox whose read status is true) to none -- see read status is TRUE

or you could put it in the startup items.

Thanks Stefan,

So this script will only help when I re-open Mail?

Or will this updated script you just gave me work simultaneously as your other one you provided me a few days ago?

Are both the scripts you provided me running in the background at all times while I have the application mail open?

Thanks,

-Blake

You can run the script to change the color to red using a mail rule, that works automatically.

But there is no event to do something when a message is opened.
So you have to start the second script manually or put it in the startup items then it will be always executed during the startup process of the computer

I can’t set the background color of a message. In the following code, the flag index and read status are correctly set, but the background color does not change.


tell application "Mail"
	activate
	set flag index of the first message of inbox to 1
	set read status of the first message of inbox to true
	set background color of the first message of inbox to red
end tell

Carl

Mail 8.2, Yosemite 10.10.5

Browser: Safari 600.8.9
Operating System: Mac OS X (10.10)

Hey Carl,

On my system (10.10.5) changing the background color of a message with AppleScript does not APPEAR to work, but in fact it does work.

If I switch to another mailbox and back to force the current mailbox to refresh, the color change shows up.

This issue also affects color changes I make with rules in Mail Act-On.

I’ve tested both with the MAO plugin installed and not-installed.

I have a simple Keyboard Maestro macro to accomplish this mailbox refresh, which I have been using for 5+ years to remove read messages from the current view. It works for this task as well.

Now then ” after some experimentation I find I can force the message background color to refresh in the script by doing something like this:


tell application "Mail"
	set msgList to (messages of inbox whose read status is false)
	repeat with i in msgList
		tell i
			set background color to red
			set read status to true
			set read status to false
		end tell
	end repeat
end tell

-Chris


MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.10.5

Thanks Chris, but neither switching mailboxes nor using your code sample worked for me with Mail 8.2 (2104) on Yosemite 10.10.5. Are you using Mail 8.2 (2104)? The reason I ask is that I went back to previous versions of Mail (Mail 7.3 (1878.6) on Mavericks 10.9.5 and Mail 8.2 (2098) on Yosemite 10.10.3) and your suggestions did work as you described. If you are using the same version of Mail, then I’m thinking that my Mail app may have gotten corrupted (although this is the only problem with scripting Mail that I have seen).

Carl

For me, Mail 8.2 (2104) the script behave flawlessly without the set read status instructions but leaving them doesn’t hurt.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 31 août 2015 17:53:53

Hey Carl

I was using the normal version of Mail for that OSX.

I’m now using OSX 10.11,and I’ve revised my script to be less clunky.


tell application "Mail"
	tell (messages of mailbox "Testing" whose read status is false) to set its background color to red
	
	tell (some message viewer whose index is 1)
		set selected mailboxes to {mailbox "Email Lists/Smile" of application "Mail"}
		set selected mailboxes to {mailbox "Testing" of application "Mail"}
	end tell
end tell

I’m not using the InBox for my tests.

It’s a good idea to create an empty mailbox to use to “refresh” the current one, so Mail doesn’t have to work to display anything.

On my system this works in a flash for just a few emails. 100 emails takes about 2.5 seconds.


Chris


MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11

Hi Chris,

This still doesn’t work on my system. I’m going to wait until I upgrade to El Capitan and then try again.

Carl

Hey Carl,

I have a feeling you didn’t use my idea of refreshing the mailbox by shifting the selected mailbox elsewhere and back again.

Try this:


tell application "Mail"
	
	# Use your own EMPTY mailbox in place of "A_TEST_BACKUP".
	set refreshMBX to mailbox "A_TEST_BACKUP" of application "Mail"
	set msgList to (messages of inbox whose read status is false)
	
	repeat with i in msgList
		tell i
			set background color to red
		end tell
	end repeat
	
	tell (some message viewer whose index is 1)
		set selected mailboxes to {refreshMBX}
		set selected mailboxes to {inbox}
	end tell
	
end tell


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Sorry Chris, I just can’t get the background color to change. I’m now on El Capitan 10.11.0 and Mail 9.0. I put in some delays so I could see what was happening. The “set flag index to 4” does work but the “set background color to red” does not.

tell application "Mail"
	
	# Use your own EMPTY mailbox in place of "A_TEST_BACKUP".
	set refreshMBX to mailbox "Test" of application "Mail"
	set msgList to (messages of inbox whose read status is false)
	
	repeat with i in msgList
		tell i
			set flag index to 4
			delay 2
			set background color to red
			delay 2
		end tell
	end repeat
	
	tell (some message viewer whose index is 1)
		set selected mailboxes to {refreshMBX}
		delay 2
		set selected mailboxes to {inbox}
	end tell
	
end tell

Carl

Hey Carl,

Well shoot! You’ve got gremlins… :expressionless:

-Chris