Mail · AppleScripts

Set Message Color

    An AppleScript to quickly set the background color of the selected email messages in Mac OS X Mail. This is useful e.g. to keep track of the status of ordered items.

Screenshot of colored messages

Unfortunately, it is not possible to use arbitrary RGB colors so you have to stick with the seven colors that are availble.

Screenshot of Set Message Color

Save the script to ~/Library/Scripts/Applications/Mail/ and run it via the AppleScript Menu or use a third-party application like FastScripts to easily assign a keyboard shortcut to the script.


show source AppleScript Editor open download
--   Creation date:    Freitag, 4. November 2011, 15:25:51
--   Created by:        luke (http://applescript.bratis-lover.net)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                                     SETTINGS
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

property myName : "Mail · Set message color"
property myVersion : "1.0"

property lastColor : {} -- store the last selection


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                               DESCRIPTION
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

(*
An AppleScript to quickly set the background color of the selected email messages
in Mac OS X Mail. This is useful e.g. to keep track of the status of ordered items.

Unfortunately, it is not possible to use arbitrary RGB colors so you have to stick
with the seven colors that are availble.

WWW: http://applescript.bratis-lover.net/applescripts/mail/set-message-color/
*)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                                            MAIN
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --


tell application "Mail"
        
        --c-- get and count selected messages, abort if no messages selected 
        set sel to selection
        set len to count sel
        if len = 0 then
                display dialog "No message(s) selected!" with icon 2 ¬
                        with title myName buttons {"Cancel"} cancel button ¬
                        1 default button 1 giving up after 3
                if gave up of result then error number -128
        end if
        
        --c-- prompt for color
        set col to choose from list {"blue", "gray", "green", "none", "orange", ¬
                "purple", "red", "yellow"} with title myName with prompt ¬
                "Choose background color for " & len & " selected messages:" default items ¬
                lastColor OK button name "Set color" cancel button name "Cancel"
        if class of col is not list then error number -128
        set my lastColor to col -- store last selection
        set col to col as text
        
        --c-- apply color to messages
        -- The background color property accepts only six default colors.
        -- It is not possible to store a color in a variable or to use
        -- RGB colors.
        repeat with i from 1 to len
                if col = "blue" then
                        set background color of sel's item i to blue
                else if col = "gray" then
                        set background color of sel's item i to gray
                else if col = "green" then
                        set background color of sel's item i to green
                else if col = "none" then
                        set background color of sel's item i to none
                else if col = "purple" then
                        set background color of sel's item i to purple
                else if col = "red" then
                        set background color of sel's item i to red
                else if col = "yellow" then
                        set background color of sel's item i to yellow
                end if
        end repeat
        
end tell


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                              TERMS OF USE
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

(*
This script was written by ljr (http://applescript.bratis-lover.net).

It is released under the following terms:

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*)