Improved AppleScript to Automatically Insert Recipient’s Name in Apple Mail using TextExpander

Years ago I published an AppleScript that allows you to automatically insert a recipient’s name to an email using TextExpander on your Mac. This is a cool trick because when you use it, you never get a person’s name wrong when replying to them. 

Reader Greg (Twitter) wrote to me about the script a while back. One of the flaws with my script was that if the email was written in a way that listed the recipients last name first (e.g., Sparks, David), the script didn’t work correctly. As I wrote it, the script required the person’s first name to be listed first.

Greg broke out his AppleScript editor and made a few changes. The new version is below:

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) and (theToRecipient does not contain ",") then
                    return word 1 of theToRecipient
                else if ((count words of theToRecipient) is greater than 0) and (theToRecipient contains ",") then
                    return word 2 of theToRecipient
                end if
            end if
        end tell
    end tell
end tell

The new version looks at the number of words and looks for a comma. If it finds a comma, it uses the second word as the recipient’s first name. In hindsight, this little addition is obvious. Nevertheless, Greg was kind enough to share this with the rest of the Internet and me through this post. You can download the script file right here.

To implement this, create a TextExpander snippet that runs as an AppleScript and includes this script.


Click to enlarge.

You can see my shortcut phrase is “xmm” (x name in my head) but I never trigger it with that phrase. Instead I embed it in other snippets with different salutations.For instance, to start it with “Hello” and a comma after the name, you would make it look like this.


Click to enlarge.

If you want to have a less formal one starting with just “Hi”, it would look like this.


Click to enlarge.

I’ve run the whole board with versions for “Hey” and “Dear” as well. You can download the TextExpander snippet group, including the script, with this link.

If you have TextExpander and use Apple Mail, I recommend trying this out. I use these scripts with nearly every email I write on my Mac. I love that it got just a little bit smarter with Greg’s tweak. Take the time to set this up. You will not regret it. Also, if you’re on Twitter, tell Greg “thanks”.

AirBuddy for Using AirPods on Your Mac

Guilherme Rambo, the gent who keeps finding scoops for 9to5Mac with some very clever sleuthing, recently published a simple app to make using AirPods with your Mac easier called AirBuddy. Once installed, it keeps an eye out for your AirPods. When you open them AirPods case you get a little animation that looks very familiar to what you see on iOS.


Screen Shot 2019-02-12 at 3.09.20 PM.png

AirBuddy can also add a widget to your Mac’s sidebar that will give you easy access to battery status.


(It’s a good thing my iMac has a 100% battery.)

(It’s a good thing my iMac has a 100% battery.)

That’s really about it. Guillermo is using a choose your own price model with a recommended price of $5. That makes it an easy purchase.

Mac Power Users 469: Running a Business with G Suite

With G Suite, Google offers paid versions of its free web apps and services. On this week’s episode of Mac Power Users, Stephen and I discuss our usage of these tools and how G Suite compares to other solutions available to individuals and small businesses. 

This episode of Mac Power Users is sponsored by:

  • The Omni Group: We’re passionate about productivity for Mac, iPhone, and iPad. 

  • SaneBox: Stop drowning in email!

  • Squarespace: Make your next move. Enter offer code MPU at checkout to get 10% off your first purchase.

  • Luna Display: The only hardware solution that turns your iPad into a wireless display for your Mac. Use promo code POWER at checkout for 10% off.

Hyper-Scheduling Without Making Yourself Crazy

There is a thread in the Focused forums referring to an article from The Guardian where a block scheduler gives herself 3-minute bathroom break blocks. I think that is too much. When the blocks get too small, you spend your time arranging your time instead of doing something. Blocks too small can start to feel like deck chairs on the Titanic.

When I started my series on block scheduling, I called it “hyper-scheduling”. That’s because I hadn’t researched it enough to realize everyone else in the world called it “block scheduling”. Regardless, and in spite of my silly name for it, rarely do I schedule a chunk of time less than an hour when I schedule my time. Looking at my current week, my only blocks less than an hour are my daily tasks of starting up and meditating, two things that I want to make sure I make time for and don’t need a full hour.

As I’m writing this, it’s Monday morning. Here’s my current schedule for the week.


Screen Shot 2019-02-11 at 7.04.09 AM.jpg

You’ll see that nearly everything is at least an hour. While most of today is booked up, there are still blocks of open space throughout the rest of the week that will inevitably fill up as I move through the week. With these one-hour minimum blocks, it is not difficult to move things around as the need arises. One last note: because it is Monday, this schedule looks suspiciously organized and symmetrical. Have no fear. By Friday, it will look a lot less organized. Shit happens.

Cameras and Microphones

I enjoyed John Gruber’s response to the Wall Street Journal piece on the risks posed by webcams. In the article, Joanna Stern for the WSJ found a white hat hacker to try and break into her webcam on a Mac an Windows PC. On the Mac, getting access to the webcam required her to download an app outside of the App Store, turn off some of its security features, and then click OK on a dialog asking for camera access. That doesn’t sound like getting hacked to me as much as just being dumb.

Most interesting to me was John’s concern about microphones.

“I’ve never understood … the complete lack of similar paranoia over microphones, which cannot be blocked by a piece of tape and which have no in-use indicator lights.”

I agree with this 100%. If there is going to be a privacy breach through your Mac that does not include you doing something silly (like clicking OK to camera access), it is going to be through the microphone. I’d love to get some indication from Apple that they are addressing this vector as well as they’ve addressed the video camera.

Jazz Friday – Ben Wendell’s Seasons

Today for Jazz Friday I want to share a contemporary saxophone player that I enjoy, Ben Wendell. Ben plays the sax and bassoon. He’s been a sideman for many artists in many genres (including Snoop Dogg!), but some of my favorite music from Ben are shorts he does with other talented musicians on YouTube. He does collections of these videos that all eventually turn into albums. Lately, I’ve been listing to the Seasons collection and enjoying it. You can get the album on Apple Music and below is one of my favorite videos in the collection.

The 2019 Emoji with 100% more Otter


Screen Shot 2019-02-08 at 1.33.37 PM.png

I’ve come a long way in my relationship with Emoji since they first appeared on the iPhone. At this point, I use them every day, and I do think they can convey a certain level of emotion with text with the right people. Meanwhile, the emoji machine keeps rolling along. According to Emojipedia, we’ve got 230 more Emoji heading our way in 2019. I like the way the emoji library gets more inclusive every year. Two significant additions this year are people with disabilities and couples of all colors and types. Sign me up. The idea of my very own Otter emoji is also pretty cool.

Focused 66: Putting Email in Its Place

On this week’s episode of Focused, Mike and I navigate the minefield of email. We share strategies and workflow tips to help you curb inbox addiction and reclaim your focus.

This episode of Focused is sponsored by:

  • Timing: The automatic time tracking app for macOS. Use this link to save 10% on your purchase.

  • FreshBooks: Online invoicing made easy.

  • Squarespace: Make your next move. Enter offer code FOCUSED at checkout to get 10% off your first purchase.

AppleScript to Link to Apple Mail Message

I’ve always like the way OmniFocus can create links to Apple Mail messages when saving an email as a task. With help from listener Jacob (@evansio), I’ve now got a script that can do that anywhere via a text expander snippet. Here’s the AppleScript:

(*
  Returns a link to the first selected Apple Mail message
*)
tell application "Mail"
  set _msgs to selected messages of message viewer 0
  if (_msgs is not equal to missing value) then
    set _msg to first item of _msgs
    set _msgID to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & (message id of _msg)
    return "message://%3C" & (_msgID) & "%3E"
  end if
end tell

Here is that script embedded in a TextExpander Snippet. I’m using the abbreviation “elink”


Screen Shot 2019-02-05 at 7.19.58 AM.png

That’s it. Once you’ve installed it, just type “elink” in any app that can take a URL and you create a link to the currently selected email message. I use it all the time in Notes and Calendar note fields but it really works anywhere. Here’s a short explanatory video.