Using AppleScript to Announce Glanceable Information

Ernest Rudak (Twitter)(website), a blind Mac power user, wrote a really informative piece on using AppleScript to announce glanceable information. Of course, as someone who’s not visually impaired, there are a lot of things I take for granted or never really thought about, like getting information like time, day, or date with a quick glance on my iPhone. Ernest, with an interest in automation, Keyboard Maestro, and keyboard shortcuts, came up with a solution by writing an AppleScript. Have a go and read it for yourself to see what works for him. I agree with him that the best automations aren’t the ones filled with endless lines of code, but the “small utilities which smoothly fits in your everyday workflow.”

The Sad Demise of the Harmony Remote

Harmony Remote.JPG

Last week we got notice that Logitech will no longer be making the Harmony remote. I’ve heard from so many listeners and readers over the years who made the Harmony remote an essential piece of their home-automation infrastructure. I tried using one but found it just didn’t work with my brand of TV. Nevertheless, I could see the clear value it had.

It’s interesting that as we go deeper down this rabbit hole of Internet-of-Things, we’re losing a vital tool for many people. Maybe the answer going forward is for TVs to become more automation aware, but I suspect that is asking a lot in an already low-margin business.

If you have an existing Harmony remote, Logitech promises ongoing software updates, but I don’t expect that to last forever. I’d start looking for your Plan B.

The Idea of Shortcuts on the Mac

This week Jason Snell wrote an excellent article about the need for Apple to bring Shortcuts to the Mac. I’ve been thinking about that article a lot. My position on Apple bringing Shortcuts to the Mac has always been, “wait”. The reason being that automation is alive and well on the Mac. With a much more open platform and the existence of Apple events, AppleScript, Keyboard Maestro, Hazel, TextExpander, and the ability to run virtually any scripting language via the terminal, there is very little that I can not automate on my Mac.

The iPhone and iPad, however, are a much different story. Apple had no automation tools on its mobile platforms until Shortcuts came along. Shortcuts is, practically, the only way to automate on mobile and for years now there has been lots of low-hanging fruit on mobile that Shortcuts has yet to pick.

I wanted Apple to keep the Shortcuts team working exclusively on mobile so it could get better rather than spend its time moving Shortcuts over the Mac. However, Jason’s article has moved me on this. While my argument about waiting made sense a few years ago, nowadays we’ve got Apple Silicon Macs and Shortcuts on mobile is a lot more powerful than it used to be. Moreover, even with all the above-mentioned Mac automation tools, there is room under the tent for one more. If done right, we’d be able to pull Shortcuts actions into scripts and Keyboard Maestro and make those tools even more powerful.

So put me on team Mac Shortcuts. Let’s hope WWDC 2021 brings us Automators some new toys.

ThoughtAsylum Icon Generator

Stephen Millard has made an ingenious shortcut that solves the problem of generating icons. The particular itch that Stephen was trying to scratch was the development of icons for his Stream Deck. However, if you do any automation, you're constantly bumping into places that you'd like to have icons. One of the things I particularly like about Stephen's solution is the way it works with Apple's SF Symbols, which I like.
Either way, if you want to render 10 or 10,000 icons this weekend, check this out.

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.

Masters of Automation on Upgrade Podcast

Last week I attended the first ever CMD-D: Masters of Automation conference in San Jose. At the end of the day, Jason Snell did a live on-stage podcast with all the speakers, including yours truly. 

The show went live this week in the Upgrade feed. I though it came out great and there is a lot of good information about where we stand with automation technologies with both Mac and iOS. The CMD-D portion starts about 30 minutes into the podcast but I recommend listening to the whole thing.

The CMD-D Mac Automation Conference

When we had Sal Saghoian on the Mac Power Users a few months ago, I observed that one of the best things about him leaving Apple is that he gets to share more with us automation-loving nerds. It looks like Sal is pretty serious about that because he is putting on a conference with Paul Kent (the former conference organizer for Macworld Expo). CMD-D is a one day conference in August in Santa Clara all about Mac and iOS automation.

If you're thinking about attending, I'd recommend it. I took a two-day AppleScript course from Sal several years ago and can attest that he's not only very knowledgeable on the subject of automation, he's also a great teacher. Learn more at the CMD-D website.

Automating PDF Creation from Image Files on the Mac

Recently a client sent me a contract electronically by taking a series of photos of a document. This happens to me once in a while, and usually I open the individual images in Preview, combine them, and save them as PDF. I received another such series of photos this morning and finally decided to automate this process so I don’t have to do it manually anymore. Automator to the rescue.

Why I Love Automator Services

Automator has the ability to create Services. These are little programs that reside in the contextual menu on your Mac. Right-clicking on a file gives you an option to employ Services. The nice thing about Services is that they stay out of the way until you need them, and then they are there, just a right-click away. (All screenshots in this post will get bigger on your screen if you click them.)

So I decided to make my little automation routine for combining PDF files a Service. This happens after you open the Automator App and click New in the File menu. 

In order to get to the Services menu, you’ve already selected a file. This means the Services don’t need the typical file-selection nonsense. To run the Service, you’ll first select the images you want to combine and convert to PDF. Clever, right?

Because the Service we are creating is made specifically to turn images into PDFs, we don't want our Macs to try and use it against other types of files such as text files or music files. Therefore, we will limit the Service so that it only works when it receives image files.

Now Let’s Get Automating 

If you’ve never used Automator before, don't sweat it. It's easy. Automator has a series of tools on the left side that you drag into your workflow on the right side. You stack those together like LEGO bricks and at the end you've created a program. This Automator workflow has just two bricks. The first thing we’ll need to do is take the existing images and convert them into a single PDF.

Fortunately, Automator has a tool specifically for this job named, not surprisingly, "New PDF From Images". Go in the Search bar for Automator and type "new PDF”, and the search gets you there. 

Drag the tool into the workflow area and we’re halfway there.

The Quartz Filter

We could really stop with just the one step and convert the images to PDF, but there is still a problem. Photos converted to PDF still make lousy documents. They have lots of color and are hard to read. 

MacOS has quartz filters built in that can change the way a PDF looks. There’s also an Automator tool to apply a quartz filter right in your workflow. So go ahead and search for “quartz”.

Drag the “Apply Quartz Filter to PDF Documents” tool into the workflow. When you do that, however, you’ll get the following dialog.

This dialogue is Automator being extra careful that you don’t override something you want to keep. For this workflow, I clicked “Don’t Add”.

After that, you’ll see the workflow with both steps.

You’ll note in the above screenshot that the quartz filter isn't doing anything yet. Time to change that. Click on the arrow next to the filter and select "Black & White". This converts the color image to a black-and-white image and makes the document much easier to read and edit.

That’s it. Save the script, select some images, right-click on them, and try it out from your Services menu.

“Super Important”

There’s a small tidbit at the end of John Gruber’s post about the new Mac Pros.

I asked about scripting and automation — whether Apple still sees scripting and automation as an important part of the pro market. Federighi: “We think scriptability and automation of the system remain super important.”

I'd agree. Power users and large company deployments all rely on scripting to get their work done faster. Craig Federighi’s affirmation about scriptability and automation here is re-assuring but, at the same time, Apple is sending some mixed messages:

  • Apple laid off Sal Soghoian, the biggest advocate of automation and scriptibility. Sal not only got users excited about these tools, he was also fighting the fight inside Apple to make sure automation and scriptibility got updates with the operating system and inside Apple’s own software.
  • Apple not only laid off Sal, they eliminated his position. As Sal explains, “Recently, I was informed that my position as Product Manager of Automation Technologies was eliminated for business reasons.”
  • Apple has been very slow about pushing automation forward on iOS. The current URL-scheme automation methods exist because of clever developers, not Apple. While extensions are a start, there needs to be more.
  • On the plus side, Apple purchased Workflow, a leading automation app for iOS. Some are worried that this acquisition spells doom for the future of Workflow. I think they are going to fold it into the operating system making it (possibly?) even better.

I agree with Craig Federighi that automation and scripting is “super important” but I’d also remind him that if that is the case, we need more than words right now. WWDC is just a few months away and it sure would be nice to see that Apple is moving the ball forward for automation and scripting.

Automating Invoice Processing on My Mac

When I first opened my solo law practice, one of the unanswered questions in my mind was how I would go about billing clients. This is supposed to be hard. Some law firms spends days every month on getting bills out the door. Others pay outside vendors. I decided to nerd the s%*t out of this problem and do it myself.

I use an online practice management solution, Clio, to track my time. At the end of the month, the service creates PDFs of my invoices that go into my Mac's Downloads folder. Rather than show an actual client invoice, I'll use this dummy invoice for my side landscaping business.

One of the tricks of this workflow is that when I push a button in Clio, the PDF is created and opens automatically on my Mac in the Preview application. The first tool to help me automate the process is Hazel. I've talked a lot about Hazel at this site and on the podcast over the years. One of Hazel's many talents, is the ability to identify, name, and move files. So I've got Hazel constantly looking at my Downloads folder. If it sees a PDF file that has the text "Lawn Care Products and Livestock", "PO number", and "Gunther's Gardening", it will start acting on that file. My logic is that there will be no PDFs in my Downloads folder that have all of those words in that order that are not an invoice. Here's the Hazel Rule.

Once Hazel finds a match, usually within seconds of the file downloading, Hazel renames the file with the current date, client name, and a further description of the invoice. Because the PDFs open on my desktop at the time of the download, it's fun to watch the name change as I'm reading the invoice over. Next Hazel moves the invoice to a folder I've designated in the client's Admin/Invoices folder.

So within seconds of downloading the invoice, my Mac has named and moved the invoice to its appropriate folder.

Next I click on the sharing button in the Preview App (which is diplaying the invoice). From there I click on the Mail icon and this creates a new blank email with the invoice already attached.

My next big tool is TextExpander. I manually type in the client's name as an email recipient. Then I tab down to the s ubject line and fire off a TextExander snippet. The snippet phrase is "newbill". The snippet first fills in the subject line with the terms "Sparks Law %B Invoice" which TextExpander fills in as "Sparks Law October Invoice". Next month the snippet will automatically change "October" to "November". (TextExpander recognizes the wildcard %B as the current month.)

Next, the snippet asks me to fill in the client name and let's me choose from several frequent options. Three common issues in these cover emails are questions about whether the client wants to pay online via credit card, wants a snail mail copy of the invoice, and if there is someone else at the company that needs to get the invoice. I use TextExpander Optional Selection phrases for this. I can check or uncheck the appropriate phrases for the particular invoice.

Finally,  I have a multi-line field at the bottom where I can write or dictate in a further description of services or plans for the coming month.

Here is the finalized email from the above snippet screen.

Here is a screenshot of the snippet form TextExpander.

Here is the full text of the snippet if you want to adapt it for use use it in your copy of TextExpander at home.

Sparks Law %B Invoice
%key:tab%Hi %filltext:name=field 1%,

Attached is this month’s invoice. %fillpart:name=online pay:default=yes%I also sent you a separate email with online payment instructions if you’d prefer to pay that way via credit card.%fillpartend% %fillpart:name=optional part 3:default=yes%Also, please let me know if you’d like hard copies of these invoices in the mail.%fillpartend% %fillpart:name=someone else:default=yes%Finally, if you’d like me to direct these to someone else at the company, let me know.%fillpartend%

%fillarea:name=Message:default=Thank you for your business.%

Kind regards,

David Sparks
Sparks Law
SparksEsq.com

So this detailed explanation probably sounds like a lot but in action, the whole process is wicked fast. It takes just moments for me to approve and download a PDF invoice, at which point my Mac names and files the invoice, and I send it off to the client with a customized email. I love being a nerd.

As an aside, I have had very few clients take me up on the offer to get snail mail invoices. Almost everyone wants things in just PDF form. I have brilliant clients.

Service Sunday - Text to iTunes Audio

One of my very favorite web services is Instapaper. It allows you to clip any webpage for later reading. The trouble is, Instapaper makes it so easy to mark articles for later reading that I tend to mark many more articles than I can possibly find time to read. In effort to keep up with the deluge, I decided to start converting some of the articles to audio tracks.

Before digging in, let’s talk about what this service will do. You can highlight any selection of text, including an Instapaper article, and right click into a service that will grab the text, convert it to an audio file, rename it, and dump it into an iTunes playlist. This is remarkably easy. You just need Snow Leopard 10.6, a little patience, and about 15 minutes. So load up Automator and let’s get started.

The Automator Script

If you’ve never used Automator before, you’re going to love it. Automator lets you program your Mac without knowing how to program.

When you first load up Automator, you will be prompted to choose your workflow. For this project, choose to make a Service. This lets you to activate it contextually (right clicky). So click on Service and move along.

This service will accept text from any application. I normally use it in Safari, but it will work with Pages documents, long e-mails, RSS readers, and any other place that you have lots of text.

So Automator is kind of like programming tinker toys. You get one piece and connect it to the next. The first piece, called “Text to Audio,” converts accepts text and spits out an AIFF file. The easiest way to find it is typing “text to audio” in the search window.

Drag the action over and your screen should look like this.

This first step is the most important. It grabs text and converts it into an audio file. I save the audio file to the desktop with a temporary name “T2A”. The workflow will trash the file later.

Next, the workflow renames it with the “Rename Finder Items” action. By enabling the “Show this action when the workflow runs” option, you can type in a name when the service runs.

Next, the service imports the file to iTunes with the “Import Audio Files” action. Ticking the box, “Delete source files after encoding” cleans up your desktop for you.

Finally, the service adds the audio file to an existing playlist. I created one called, “Fascinating Text.” Here is the whole workflow.

For bonus points, set up a Smart playlist in iTunes that grabs all unplayed files from the Fascinating Text playlist and sync it to your iPhone/iPad/iPod and you are set. Wherever you go, great listening materials are a click away.

In Action

Just highlight some text and activate the service. I usually do it from the Readability view in Safari. For long articles, this can take several minutes.

Then give it a name.

Then Automator does the rest. If its a large file, this also can take awhile. Open iTunes and play.

The articles I most often convert to audio are non-techy long form pieces. So often, reading Mac and Legal stuff results in new OmniFocus tasks for me so I prefer to put in text like New Yorker or New Republic articles. Literature would work but the voice isn’t natural enough. I tried “To Kill a Mockingbird,” but listening to Alex recite Atticus Finch made me want to push an icepick in my ear.