Add a glossary of text strings to Mail.app

Oct 04, '04 09:32:00AM

Contributed by: Tom Robinson

I have a number of pre-defined text strings I like to insert into e-mail messages--address, bank account, etc. I've written a 'quick & dirty' AppleScript to do this for me. You may find it useful too, or as the basis for a fully-fledged script.

In my ~/Library -> Scripts -> Mail Scripts folder, I've created a Glossary folder, and in there, I have a number of these scripts (identical except for the GlossaryEntry property). To insert into an e-mail, just position the cursor at the appropriate point in the body of the message, and run the script from Mail's scripts menu.

Here's my Address entry script:

-- 2004-06-24 Tom Robinson

property GlossaryEntry : "Tom Robinson" & return & ¬
  "xx Garfield Street" & return & ¬
  "Brooklyn" & return & ¬
  "Wellington" & return & ¬
  "Aotearoa New Zealand" & return

KeyIt(GlossaryEntry)

on KeyIt(WhatToKey)
  tell application "System Events"
    set CharBuffer to ""
    
    repeat with i from 1 to number of characters in WhatToKey
      set ThisCharacter to character i of WhatToKey
      if ThisCharacter is "'" then
        keystroke CharBuffer
        set CharBuffer to ""
        keystroke "}" using option down
      else if ThisCharacter is "—" then
        keystroke CharBuffer
        set CharBuffer to ""
        keystroke "_" using option down
      else if ThisCharacter is "…" then
        keystroke CharBuffer
        set CharBuffer to ""
        keystroke ";" using option down
      else if ThisCharacter is "–" then
        keystroke CharBuffer
        set CharBuffer to ""
        keystroke "-" using option down
      else
        set CharBuffer to CharBuffer & ThisCharacter
      end if
    end repeat
    
    if CharBuffer > "" then keystroke CharBuffer
  end tell
end KeyIt
Special characters like ellipses and em-dashes were causing problems for keystroke, that's why they're special-cased above. Note: 'Enable access for assistive devices' needs to be turned on in the Universal Access System Preferences panel in order for this to work.

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2004092815480274