Previous  |  Main  |  Next
AppleScript Logo

Label Selected Messages

Script for: Mailsmith 1.x, 2.x (OS 9 & OS X)
Copyright: Matthias Steffens, use at your own risk!
Description: This script will label any selected messages with the label specified
in the property "LabelIndex".

Makes use of the "Get Selection v1.2" script framework, which means:
the script code of the "Get Selection v1.2" script (i.e. the "GetSel" routine)
must be appended to the code below. (The compiled script version which
you can download below already contains this routine)
Necessary: Get Selection script framework
Download: Label_Messages.hqx
The Script:
-- this is the (n-7)th Mailsmith label ("none" has label index 0,
-- finder labels have label index 1-7), adjust to your needs:
property LabelIndex : 8 -- the label index of the label

set {selType, selList, selString} to my GetSel() -- call the "GetSel" routine

-- decide how to proceed depending on the selected items that were returned by the "GetSel" routine:
if selType is not "undef" then
	if (selType contains "message") or (selType is "text") then
		tell application "Mailsmith"
			set ct to count selList
			if ct is not 0 then
				repeat with i from 1 to ct
					set Msg to item i of selList
					my ProcessItem(Msg) -- process each message
				end repeat
			end if
		end tell
	else -- selType is either "single mailbox" or "multiple mailboxes"
		my DisplayHelp()
	end if
else -- selType is undefined (see the "Get Selection v1.2" script framework for possible cases causing 'undef')
	my DisplayHelp()
end if


on ProcessItem(theItem)
	tell application "Mailsmith"
		set label index of theItem to LabelIndex
	end tell
end ProcessItem


on DisplayHelp()
	display dialog "No message(s) selected!" & return & return & ¬
		"This script labels any selected message(s), i.e. you need to select one or more messages in order to use this script." buttons {"OK"} default button 1 with icon note
end DisplayHelp

 


Contact: Matthias Steffens  |  Previous  |  Main  |  Next  |  Last Updated: 30-May-03