Hey Folks,
Okay, I've got this working now. The version below depends upon the Satimage Osax and the '
Plain Clip' applet. I've run it from
FastScripts, and it's acceptably quick on my old G4 PowerBook. (I use FastScripts to run most key-driven Applescripts on my system, primarily because of the ease with which I can organize and edit them.)
The version I'm using on the PowerBook is run from QuicKeys and uses it to strip the text-styles. I also use QK instead of System Events to do the keystrokes, because it's a bit faster.
I'm really disappointed to not have found an Applescript method to strip styles from the clipboard text - particularly since it used to be so easy to do (even if a trifle esoteric). I'm also more than a little bit frustrated that after 7 years Mail has no Applescripted ability to set selected text. I'll spare you the bile; JD long ago said it better than I could.
Still to do is to case for different groups I send mail to.
-- It may be necessary to tweak the delay times to get this to run properly on a different system.
property lookUpTable : "
EMAIL_ADDRESS SALUTATION_TEXT
"
try
tell application "System Events"
keystroke "s" using {command down}
end tell
delay 0.2
tell application "Mail"
try
set winName to name of front window
set msg to item 1 of (messages of drafts mailbox whose subject is winName)
tell msg
set msgHeaders to all headers
end tell
end try
end tell
set fStr to "^To: (.+$)"
set rStr to "\\1"
set foundStr to find text fStr ¬
in msgHeaders using rStr ¬
regexp true ¬
with string result
set text item delimiters to " <"
set nameAddress to text items of foundStr
set text item delimiters to ">"
set item 2 of nameAddress to text item 1 of item 2 of nameAddress
set {fName, emailAddress} to {word 1 of item 1, item 2} of nameAddress
try
set fStr to emailAddress & "+\\s+(.+)"
set rStr to "\\1"
set foundStr to find text fStr ¬
in lookUpTable using rStr ¬
regexp true ¬
with string result
on error
set foundStr to "Hey " & fName
end try
set salutationText to (foundStr & return & return & return) as text
set the clipboard to salutationText
tell application "Finder"
open "Thor:Applications:Text Editors & Word Processors:Plain Clip:Plain Clip.app:"
end tell
delay 0.35
tell application "System Events"
keystroke "v" using {command down}
end tell
on error errMsg number errNum
tell application "Mail"
beep
display dialog errMsg & return & return & "Error Number: " & errNum
end tell
end try