• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Automating a Salutation in Mail
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Automating a Salutation in Mail


  • Subject: Automating a Salutation in Mail
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 8 Jul 2009 05:14:54 -0500

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.

Best Regards,

Chris

______________________________________________________________________

-- 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

email@hidden Hallo Tobe,
"

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
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Automating a Salutation in Mail
      • From: Philip Aker <email@hidden>
  • Prev by Date: Re: Vertical Bars disappear for lowercase variable names?
  • Next by Date: Retrieving a "Range" in Excel for storage in a Database
  • Previous by thread: Re: Vertical Bars disappear for lowercase variable names?
  • Next by thread: Re: Automating a Salutation in Mail
  • Index(es):
    • Date
    • Thread