Skip to content

Instantly share code, notes, and snippets.

@derickfay
Last active December 9, 2017 06:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save derickfay/4289d330677c43c0926e to your computer and use it in GitHub Desktop.
Save derickfay/4289d330677c43c0926e to your computer and use it in GitHub Desktop.
TextExpander snippet to add recipient's name to email
-- TextExpander snippet to add recipient's name to email
-- based on http://macsparky.com/blog/2015/6/automatically-add-recipients-name-to-email-with-textexapnder [sic]
-- updated to handle hyphenated first names properly
-- ( Original version would return Young for Young-Hee . This version returns Young-Hee. )
set theResult to ""
tell application "System Events"
tell process "Mail"
tell text field "To:" of window 1
if UI element 1 exists then
set theToRecipient to (value of UI element 1)
if (count words of theToRecipient) is greater than 0 then
set theResult to word 1 of theToRecipient
if (count words of theToRecipient) is greater than 1 then
if character ((length of word 1 of theToRecipient) + 1) of theToRecipient is "-" then
set theResult to theResult & "-" & word 2 of theToRecipient
end if
end if
end if
end if
end tell
end tell
end tell
return theResult
@derickfay
Copy link
Author

Original version would return Young for Young-Hee . This version returns Young-Hee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment