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.

Find Files Like a Boss with HoudahSpot (Sponsor)

This week I'm pleased to welcome back HoudahSpot as a sponsor. Apple’s Spotlight search is a powerful tool. But imagine if there were a group of engineers at Apple that wanted to turn up the Spotlight search a notch or two and had nobody in management to tell them "no". That's what you get with HoudahSpot. 

HoudahSpot is like Spotlight, but better in every way. It improves upon Spotlight to let you find files by multiple criteria, like name, text, content kind, author, recipient, and pixel count to name a few. You can combine these search criteria to drill in quickly and choose which locations HoudahSpot looks in and which locations it ignores. Need to find every file that includes the name “bumfuzzle” but also includes the word “cumquat” in the text and was written in 2017? HoudahSpot can do that for you. You can even set up templates for repeat searches.

I've used HoudahSpot for years and if you haven't tried it yet, you should. The thing about HoudahSpot is that with all of that search criteria, it’s just faster. It’s faster than a Finder search, it’s faster than a Spotlight Search, and it’s faster than a Siri search. I’ve not found any easier way to laser in on just the files you want. With HoudahSpot you can find a needle in a haystack.

Anyway, don't take my word for it, go try out the app. If you like it, you can get 20% off with the coupon code MACSPARKY2019 or purchase through this link. There's no better way to search your Mac.

Mac Power Users 468: Mixing Macs and Microsoft with Christina Warren

Christina Warren, tech commentator, podcaster, and Cloud Developer Advocate at Microsoft, drops by this week’s episode of Mac Power Users to talk about using a Mac at work, the state of PowerPoint, and how to get the most out of tech when traveling the world.

This episode of Mac Power Users is sponsored by:

  • Hover: Show the world what you’re passionate about with 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.

  • TextExpander, from Smile: Recall your best words. Instantly, repeatedly. Get 20% off your first year.

  • 1Password: Have you ever forgotten a password? You don't have to worry about that anymore.

Automators 16 - Yoga Automation with Myke Hurley

The latest episode of Automators is live and ready for download. This time we are joined by Myke Hurley, who is relatively new to the automation game but nevertheless found many relatively simple, yet clever, ways to use automation to get through his day faster. Subjects include iOS automation and Siri Shortcuts, a automation-based calculations, uses for Zapier, and yoga!

Outline like a Pro with Omni Outliner (Sponsor)

This week MacSparky is sponsored by OmniOutliner, the best outliner available for the Mac, iPad, and iPhone. OmniOutliner combines powerful outlining tools plus a smart, simple interface to allow you to make beautiful outlines that can be as complex as you need them to be and no more than that. With smart columns, scriptability, custom styles, and templates, you can't go wrong. You can share your data between all versions of OmniOutliner, so you always have your outlines available to you.

I use OmniOutliner to outline contracts and complex legal transactions for my day job. I also use it to outline all of my field guides. The combination of powerful outlining tools with synchronization across all of my devices is a winner for me. No matter where I am if I think of something I want to add to the next field guide, OmniOutliner is right there waiting for me to update it. I've heard from listeners and readers that use OmniOutliner for all sorts of things, like writing a novel, creating a family tree, or just collecting their thoughts.

To learn more, head over to the OmniOutliner website and download the free trial today.

The Latest iPad Videos Get It Right

Last week Apple released a collection of new videos about getting work done on the iPad. I finally got around to watching them today and they are really good. What I like about them is that each video takes its time demonstrating actual workflows. I think that is what we need to see if we are looking to get more out of the iPad. They even call out specific non-Apple apps.

I also appreciate how they demonstrate more real-world uses. Instead of using the iPad with scuba gear to map an ancient wreck, they have people taking notes and making presentations. Not nearly as sexy as prior "iPad use" videos but so much more relevant to most of us.

These are some of my favorite tutorial-ish content that I've seen from Apple in years. They even have a film showing how they shot the videos with the iPad itself. Keep them coming Apple.

Mac Power Users 467: Fitness Apps & Tech

On this week’s episode of Mac Power Users, Stephen and I discuss how the iPhone and Apple Watch can be helpful in managing health and fitness, and coupled with the breadth of options in the App Store, they can become powerful tools in improving our well-being. 

This episode of Mac Power Users is sponsored by:

  • 1Password: Have you ever forgotten a password? You don't have to worry about that anymore. 

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

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

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

Automate Your Text with TextExpander (Sponsor)

icon_TextExpander512.png

This week MacSparky is sponsored by TextExpander. Copy and paste is an inefficient way to keep track of the things you type again and again. TextExpander makes you more productive by taking care of all those words and phrases for you. TextExpander works in all your apps so you can use it everywhere, like Microsoft Word and Excel, Adobe Illustrator and InDesign, and Apple’s Pages.

TextExpander does way more than that. With TextExpander you’ll see your snippets everywhere. It syncs between your Mac, iPhone, iPad, and Windows PC instantly.

They’ve got free snippet groups for all sorts of folks including job recruiters, freelancers, airport codes, brand names, and more at the TextExpander website (or you can download some of mine).

TextExpander even lets you run AppleScripts. For example, I use TextExpander to auto address emails with Apple Mail.

Best of all, with TextExpander you don’t have to work alone: TextExpander for Teams lets you manage and share snippets with your coworkers or the entire company. Use this link to get 20% off


The Future of Twitter

Stephen Hackett wrote a short post last week about a couple of data points that make him worry about the future of Twitter. In addition to Stephen’s points, I'd add to the list a concern that Twitter is trying way too hard to turn itself into a Facebook-level revenue generator when, fundamentally, that’s just not the Twitter we all originally signed on for. It is this limited scope that makes me like Twitter, and the harder they try to become a huge ad-selling platform, the more turned off I get.

I'm not certain the service is doomed. This is probably wish-casting, but I believe Twitter could be more successful in the long run if it simply went back to he original vision.