Last active
December 9, 2017 06:39
-
-
Save derickfay/4289d330677c43c0926e to your computer and use it in GitHub Desktop.
TextExpander snippet to add recipient's name to email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original version would return Young for Young-Hee . This version returns Young-Hee.