100% found this document useful (1 vote)
731 views

Take Control of Automating Your Mac (5.0)

Uploaded by

RAJZSPORE
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
731 views

Take Control of Automating Your Mac (5.0)

Uploaded by

RAJZSPORE
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 292

EBOOK EXTRAS: v5.

0
Downloads, Updates, Feedback

TAKE CONTROL OF

AUTOMATING
YOUR MAC
d l y g u i d e t o
A frien g )
( o r c r e a t i n
finding c u t s .
s h o r t
time-saving

by JOE KISSELL
$14.99

5 TH
EDITION
Table of Contents
Read Me First ............................................................... 6
Settings vs. Preferences ..................................................... 7
What’s New in the Fifth Edition ............................................ 7

Introduction ................................................................ 8

Automation Quick Start ............................................. 10

The State of Mac Automation ..................................... 12

Develop an Automator’s Mindset ............................... 16


Learn the Basic Principle of Automation .............................. 17
Learn What You Can Automate .......................................... 18
Look for Automation Opportunities ..................................... 19
Pick the Right Tools ......................................................... 26

Use Built-In Automation Features ............................. 28


Use the Mac’s Built-In Keyboard Shortcuts .......................... 29
Make Your Own Keyboard Shortcut .................................... 32
Use and Customize Toolbars.............................................. 35
Use macOS Text Substitutions and Transformations .............. 37
Control Your Mac with Your Voice ....................................... 40
Update Apple and Mac App Store Software Automatically ...... 47
Update Non-Mac App Store Software Automatically .............. 52
Work with Rule-Based Searches ........................................ 53
Create and Use Smart Containers ...................................... 57
Deal with the Mac’s Evolving Security Features .................... 59

Automate Your Input Devices .................................... 69


Use Trackpad and Magic Mouse Gestures ............................ 70
Use BetterTouchTool ........................................................ 72
Customize Your Touch Bar ................................................ 73
Save Clicks with Third-Party Input Devices .......................... 75
Program an Input Device with USB Overdrive ...................... 77

2
Control Anything with a Stream Deck ................................. 77
Learn About Other Special Input Devices ............................ 78

Automate Text Expansion .......................................... 80


Use Text Replacement in macOS ........................................ 81
Use a Third-Party Text Expansion Utility .............................. 83

Automate the Finder .................................................. 87


Use Spotlight as a Launcher .............................................. 87
Use a Third-Party Launcher ............................................... 90
Organize Files with Hazel .................................................. 95

Supercharge Your Clipboard ...................................... 98


Learn What a Clipboard Utility Can Do ................................ 98
Use a Macro or Launcher Utility ....................................... 100
Use a macOS Clipboard Utility ......................................... 102

Automate Individual Apps ....................................... 103


Automate Microsoft Office ............................................... 103
Automate Nisus Writer Pro .............................................. 111
Discover Other Internally Scriptable Apps ......................... 121

Automate Email ....................................................... 124


Use Server-Based Rules .................................................. 125
Automate Apple Mail ...................................................... 126
Automate Outlook Email with Rules .................................. 135
Automate Other Email Apps ............................................ 136

Automate the Web ................................................... 137


Log In Faster with iCloud Keychain and Safari Autofill ......... 137
Automate Web Logins with a Password Manager ................ 145
Automate Cloud Services ................................................ 147
Discover Other Web Automation Options ........................... 151

Automate Backup and Syncing ................................. 154


Run Backups Automatically with Time Machine .................. 155
Create Hands-Off Versioned Backups ................................ 161
Automate Mac-to-Mac Syncing ........................................ 163

3
Discover macOS Automation Technologies .............. 166
Apple’s Core Automation Technologies .............................. 166
Using JavaScript for Automation ...................................... 168
Using Swift for Automation ............................................. 170

Use Services for Systemwide Shortcuts ................... 171


Configure Services ......................................................... 172
Find and Use Services .................................................... 173

Get Started with Shortcuts ...................................... 175


Explore Shortcuts .......................................................... 176
Run a Shortcut .............................................................. 178
Import Automator Workflows ........................................... 179
Customize a Shortcut ..................................................... 181
Create a Shortcut .......................................................... 183
Share a Shortcut ........................................................... 189

Get Started with Automator ..................................... 191


Create a Simple Automator Workflow ............................... 192
Create an Automator Droplet ........................................... 195
Create Your Own Service ................................................ 198
Find and Run Sample Workflows ...................................... 203
Learn More about Automator ........................................... 203

Get Started with AppleScript ................................... 204


Write a Simple AppleScript .............................................. 204
Learn What AppleScript Can Do ....................................... 206
Understand AppleScript Basics ......................................... 208
Find and Run Example AppleScripts .................................. 213
Edit an Existing AppleScript ............................................. 217
Use GUI Scripting .......................................................... 219
Use AppleScript Folder Actions ......................................... 222
Learn More About AppleScript ......................................... 224

Script the Command Line with Shell Scripts ............. 226


Create Your Own Shell Script ........................................... 227
Try Another Script .......................................................... 230
Shell Scripts Outside the Shell ......................................... 230

4
Run Actions Automatically ....................................... 232
Use Login Items ............................................................ 233
Use Calendar Events ...................................................... 235
Use Launchd ................................................................. 238

Use Omni Automation .............................................. 252


What Omni Automation Can Do ....................................... 252
Try Omni Automation in OmniGraffle Pro ........................... 255

Use a Macro Utility ................................................... 259


Control Your Mac with Keyboard Maestro ........................... 261
Use Another Macro Utility ............................................... 279

About This Book ....................................................... 281


Ebook Extras ................................................................. 281
About the Author and Publisher ....................................... 282
Acknowledgments .......................................................... 282
Credits ......................................................................... 283

Copyright and Fine Print .......................................... 284

Also by Joe Kissell ................................................... 285

Hazel Coupon ........................................................... 286

Keyboard Maestro Coupon ....................................... 287

LaunchBar Coupon ................................................... 288

Nisus Writer Pro Coupon .......................................... 289

Script Debugger Coupon .......................................... 290

TypeIt4Me Coupon ................................................... 291

Typinator Coupon .................................................... 292

5
Read Me First
Welcome to Take Control of Automating Your Mac, Fifth Edition,
version 5.0, published in January 2024 by alt concepts. This book was
written by Joe Kissell and edited by Glenn Fleishman.

This book explores many ways to work faster, increase your efficiency,
and have more fun using your Mac by automating common activities.
Many of these techniques require no extra software, and nearly all of
them are suitable for ordinary users without special technical skills.

If you want to share this ebook with a friend, we ask that you do so as
you would with a physical book: “lend” it for a quick look, but ask your
friend to buy a copy for careful reading or reference. Discounted
classroom and Mac user group copies are available.

Copyright © 2024, Joe Kissell. All rights reserved.

Updates and More


You can access extras related to this ebook on the Web (use the link in
Ebook Extras, near the end; it’s available only to purchasers). On the
ebook’s Take Control Extras page, you can:

• Download any available new version of the ebook for free, or buy
any subsequent edition at a discount.

• Access the book in both PDF and EPUB formats. (Learn about
reading on mobile devices on our Device Advice page.)
• Read the ebook’s blog. You may find new tips or information, links
to author interviews, and update plans for the ebook.

If you bought this ebook from the Take Control website, it has been
added to your account, where you can download it in other formats
and access any future updates. However, if you bought this ebook
elsewhere, you can add it to your account manually; see Ebook Extras.

6
Settings vs. Preferences
In macOS Ventura, Apple replaced System Preferences with System
Settings, and in most apps, the Preferences menu item and window
became a Settings menu item and window. In this book, I sometimes
use a shorthand like “go to Mail > Settings/Preferences” or “open
System Settings/System Preferences” to reflect both possibilities; when
the details are significantly different, I spell them out separately as
“Ventura or later” and “Monterey or earlier.”

What’s New in the Fifth Edition


This expanded fifth edition updates the book to cover changes in
macOS 14 Sonoma. Other significant changes include:

• Updated Develop an Automator’s Mindset with a new section: Set


Up Hands-Off Triggers

• Rewrote the topic about Mail plugins, now called Automate Apple
Mail with Extensions or Plugins, to account for the fact that Sonoma
dropped support for plugins in favor of extensions

• Updated Log In Faster with iCloud Keychain and Safari Autofill to


say a bit more about the use of passkeys

• Revised Create Your Own Service with a new example of an Aut-


omator Quick Action, since Sonoma broke the one previously
included

• Added an entirely new chapter that discusses several methods for


triggering tasks of various kinds to run automatically (for example,
upon login or on a schedule); see Run Actions Automatically

• In Learn About Keyboard Maestro Actions, added information


about the Control Flow category

7
Introduction
If you’ll forgive the cliché, life is too short. I have long-term goals and
dreams that need my attention. And every single day, I have work to
do, a family to take care of, books to read, and TV shows to watch. I
don’t have time to waste on tedious tasks that my expensive, modern
Mac is perfectly capable of handling for me.

This book is about taking back your time by automating your Mac,
which sounds like a fancy and high-tech undertaking. But in fact, all I
mean by “automating” is finding shortcuts: ways to do the same thing,
only more quickly and easily, with fewer manual steps. That might be
as simple as learning a keyboard shortcut for a common command or
scheduling a task to run at a certain time. You can accomplish more
advanced automation tasks, too, by using macro utilities or writing
AppleScripts, but you might be surprised to find that some of the most
powerful and effective automation techniques require the least effort
and skill to set up. In many cases, you won’t even need extra software.

You do not have to be a programmer or computer geek to do most of


the stuff I explain in this book. I’ve written this for ordinary readers—
smart but non-technical. On the other hand, if you are a computer
geek, I do mention a few techniques that require above-average techni-
cal chops. For any kind of reader, I hope you’ll find ideas here you can
use to make your work more efficient.

Tip: If you are interested in learning about programming but don’t


know where to start, try Hour of Code.

Let me share a story. A certain bookkeeping task used to take me about


five minutes a day. After running through it a few hundred times, I
decided that I couldn’t stand it any longer. So I spent a full day work-
ing up a very snazzy macro that combined Keyboard Maestro with
AppleScript—two tools I discuss later in this book—to perform the
whole task without any intervention at all.

8
Now, you may be thinking, “That’s madness! Why would anyone spend
a whole day automating something that takes just five minutes?” Well,
I did it to save time. My calculation is that those eight hours are
equivalent to five minutes a day for about three months—so after three
months of using the macro, I get five extra minutes every single day to
spend with my kids. That adds up: it’s more than 30 hours over the
course of a year. All of a sudden that sounds pretty smart!

That’s an extreme example, as I would rarely spend so much time


automating a single task. But it nicely illustrates my objective: I invest
a bit of up-front time to shave off a few seconds here, a few minutes
there, from tasks that I perform repeatedly. My work becomes less
frustrating, freeing me up to concentrate on more interesting and
creative tasks. (And I’m now more proficient, reducing the time it takes
me to automate future tasks.) Whether I get more work done in the
same amount of time or the same amount of work done in less time,
the result is the same: higher productivity and greater happiness.

Many of the topics I discuss are deep, and I can only scratch the
surface in a book like this. For example, Sal Soghoian and Bill Cheese-
man once wrote an 895-page book on AppleScript, while I spend just a
chapter on it. Other Take Control authors penned entire titles about
Shortcuts, LaunchBar, and TextExpander, covered in this book only
briefly. And I could write hundreds of pages about Keyboard Maestro,
Nisus Writer Pro macros, and other topics. Automation is a virtually
endless subject, but I’m sure you don’t want to read thousands of pages
about it!

Instead, I want to offer you three things with this book:

• Show you lots of automation tools and techniques for your Mac.

• Offer concrete examples you can use as is or adapt to your needs.

• Inspire you with lists of further possibilities and learning resources.

The techniques in this book work with macOS 10.14 Catalina through
macOS 14 Sonoma unless otherwise noted. Most of them work in older
Mac operating systems, too—although the older your operating system,
the less likely you’ll find that everything works as described.

9
Automation Quick Start
There are dozens, if not hundreds, of ways to automate your Mac. This
book explores many of the most interesting options. I suggest that you
first read the Introduction and Develop an Automator’s Mindset. Then
dip in wherever you like and jump around to techniques that interest
you. If you’re interested in ways of automating your Mac that require
no extra software, pay special attention to the second chapter, Use
Built-In Automation Features.

Automation 101:
• Where things stand: Get a snapshot of the changing Mac au-
tomation landscape; read The State of Mac Automation.

• Strategy: Learn what you can automate and figure out where you
can save time and effort in Develop an Automator’s Mindset.

• Built-in features: Discover the many ways you can make your
Mac more efficient using nothing more than what Apple supplies in
macOS; see Use Built-In Automation Features.\

Discover what you can automate:


• Input devices: Get the most out of your mouse, trackball, track-
pad, or other input device; see Automate Your Input Devices.

• Text expansion: Insert commonly used words, phrases, variables,


and even elaborate fill-in-the-blanks reports just by typing a few
characters; see Automate Text Expansion.

• Finder: Launch apps, open files and folders, play music, look up
definitions, perform calculations, and much more with just a few
keystrokes; see Automate the Finder.

• Clipboard: Cut, copy, and paste like a pro using multiple clip-
boards, clipboard histories, and tools to manipulate what’s on your
clipboard; see Supercharge Your Clipboard.

10
• Apps: Use capabilities built into major apps like Word, Excel,
Nisus Writer Pro, and FileMaker Pro to automate repetitive or
complex actions; see Automate Individual Apps.

• Email: Eliminate spam, file messages instantly, send out automatic


replies, and more as you Automate Email.

• Cloud services: Connect cloud services to each other, create


agents that watch the web for information that interests you, and
even control your Mac remotely; see Automate the Web.

• Backup and sync: Keep your data safely backed up, and optional-
ly keep it in sync across more than one Mac; see Automate Backup
and Syncing.

Learn about Apple’s automation tools:


• Overview: Read Discover macOS Automation Technologies for the
basics of services, Automator, AppleScript, and shell scripts. Then
delve into full chapters on each:

‣ Services: Use Services for Systemwide Shortcuts

‣ Shortcuts: Get Started with Shortcuts

‣ Automator: Get Started with Automator

‣ AppleScript: Get Started with AppleScript

‣ Shell scripts: Script the Command Line with Shell Scripts

• Hands off: Use Login Items, Calendar events, or launchd to Run


Actions Automatically

Use advanced third-party automation tools:


• Omni Automation: Get a taste of the cross-platform, JavaScript-
based automation capabilities of apps by the Omni Group; see Use
Omni Automation.

• Macro utilities: Create sequences of steps you can replay with a


click or a keystroke to do nearly anything you could do yourself with
a mouse and keyboard; see Use a Macro Utility.

11
The State of Mac
Automation
When I updated this book to its third edition in 2019, I wrote about
huge changes that had taken place in the world of Mac automation in
the previous few years. Remarkably, even more changed since then, so
it’s time once again to report and reflect on the good, the bad, and the
unknowns of the Mac’s automation present and future.

In 2014, when this book’s first edition appeared, I thought Apple was
likely heading in a direction towards more and better automation
capabilities. Various Apple teams seemed to be paying greater atten-
tion to automation. Since then, signals have become decidedly mixed.

For starters, Apple laid off their key person behind automation for 20
years, Sal Soghoian, in 2016. Apple didn’t replace Sal with anyone else,
and, to all appearances, his departure from the company coincided
with a growing indifference toward Mac automation at Apple. In a
depressing shift, new and updated Apple apps began losing, not
gaining, automation capabilities via AppleScript and Automator.

In addition, Apple began removing the Unix scripting languages that


had been included with the operating system for eons. First PHP was
taken out in macOS 12.0 Monterey, and then in version 12.3, Apple
also excised Python. (As I write this in early 2024, Perl and Ruby
remain, but I suspect their days are numbered.) Although it’s still
possible to download and install those scripting languages separately,
the fact that they’re no longer included by default is an extra hurdle to
building automations that depend on them.

So that’s the bad news. And if I had written this update a few years
earlier, I might have concluded that Mac automation as a whole was on
a hopelessly downward slope. But then a crazy thing happened: Apple
took their popular Shortcuts automation app for iOS/iPadOS and

12
adapted it to work in macOS too, starting in Monterey (see Get Started
with Shortcuts).

Shortcuts lets you create automation workflows in a manner reminis-


cent of Automator. Indeed, Shortcuts can import (some) Automator
workflows, and I wouldn’t be surprised if at some point Apple ditches
Automator altogether in favor of Shortcuts. Furthermore, the shortcuts
you create on your Mac sync to, and run on, your iPhone and iPad—
and vice versa—making general-purpose cross-platform scripting on
Apple’s products a reality for the first time.

All that is excellent, and Shortcuts is in some respects more powerful


than Automator. However, it’s severely limited by the tiny number of
app-specific automation actions currently available. To be fair, some
apps have huge lists of available actions, in some cases far surpassing
their Automator support, if any existed. This includes BetterTouch-
Tool, Calendar, Camo Studio, Contacts, Keyboard Maestro, and Pixel-
mator Pro.

Generally, though, neither Apple nor third-party developers seem to


have put a lot of effort into transitioning Shortcuts from a novelty into
the sort of automation tool that professionals and businesses can count
on for mission-critical tasks.

Also in Monterey, Apple began allowing developers to create exten-


sions for Mail using a new architecture called MailKit; then, in Sono-
ma, they dropped support for the previous add-on architecture, called
plugins (see Automate Apple Mail with Extensions or Plugins). In
some respects, that set of moves across two operating systems has sort
of been two steps forward, one step back, but it’s refreshing to see
Apple put real effort into offering developers officially supported ways
to add capabilities to Mail, limited though they may be.

So where does that leave us? I don’t have any inside knowledge of
Apple’s corporate thought processes or business plans, but I can make
some informed predictions:

• Most of Apple’s automation technologies—particularly the home-


grown ones—will remain roughly the same in the next few releases

13
of macOS. Although individual apps may drop support for specific
automation technologies, I expect that most workflows you build
today with the most prominent Apple tools—Shortcuts, AppleScript,
and probably even Automator—will still be functioning in five years.

• I would like to think that Shortcuts, in particular, gains features and


gets some love from both Apple and other developers, but that’s
more of a wish than a prediction.

• Despite notable exceptions, there is little momentum among third-


party developers to increase the automation capabilities of their
apps via AppleScript, Automator, and Shortcuts. I would be sur-
prised—but delighted—if that trend turned around.

• Apple will likely continue to promote app extensions, Mail exten-


sions, cloud services, web-based tools, and—most importantly—
apps written in the Swift programming language as their preferred
ways for developers to accomplish tasks that older automation
technologies typically addressed. These tools aren’t capable enough
yet to offer all the capabilities these older technologies did, so my
hope is that as Apple works on those gaps, too.

Taking all of the above into account, including the bad news, I feel
fairly positive about a broader picture of automation on the Mac—one
that isn’t defined solely by Apple’s decisions. Here’s why:

• The Mac automation community is large, vibrant, and influential;


witness 73 Mac Automation Stories from TidBITS Readers. Notably,
some of the large groups that spend the most on Apple gear—such
as graphic artists, musicians, and various sorts of enterprise users—
depend crucially on automation technologies. I’m sure those people
collectively hold some influence over Apple’s decisions.

• In many respects, Apple takes a “let’s leave well enough alone” ap-
proach to the guts of macOS. Notwithstanding the removal of Unix
scripting languages mentioned above, there are oodles of other old
Unix utilities still kicking around in macOS. They’re not doing any
harm, and some problems might arise if they were removed, so they
largely remain in place, even without a strong argument as to why

14
they’re needed. The same could be true of today’s built-in au-
tomation technologies.

• If you depend on PHP, Perl, Python, or Ruby for automation tasks,


you’ll always be able to manually download, install, and use these
tools even when they’re not built into macOS. Indeed, since Apple’s
versions of these tools have been behind the times for a number of
years, installing fresher versions has already been quite common
among developers.

• The number of apps with their own built-in automation tools is


growing, as are the capabilities of those tools. (See, for example, the
chapter Use Omni Automation.) Even if AppleScript disappeared
tomorrow (don’t worry; it won’t), you’d still be able to automate
tasks within Acrobat Pro DC, DEVONthink, Microsoft Office, Nisus
Writer Pro, Photoshop, and many other apps. You’d also still be able
to use tools like Keyboard Maestro that use their own methods to
automate other apps.

• Even though app extensions, Swift, and so forth don’t meet the
general need for automation tools today, they’re evolving and might
eventually meet the bar. Perhaps Apple or a third-party developer
will invent some entirely new technology that will make today’s
options seem quaint.

• Apple’s Catalyst framework, which makes it simpler for iPad devel-


opers to develop native Mac versions of their apps that share most
of the same source code, fully supports AppleScript.

• Apple is paying a lot of attention to both automation and program-


ming on iOS/iPadOS—and not just in Shortcuts. Apple also (some-
what shockingly) approved Omni’s iOS/iPadOS apps that incorpo-
rate JavaScript—not just for automation within a single app, but
between apps too. And Apple offers Swift Playgrounds, a free app
that lets people learn to code in Swift on an iPad or a Mac.

In short, although I don’t know what the future of Mac automation


holds, I’m enthusiastically increasing my own use of various au-
tomation technologies, and I hope you’ll join me!

15
Develop an Automator’s
Mindset
I think of myself as a relatively lazy person. I mean, yes, I’ve written 63
Take Control books (and counting) in the last 20+ years. And yes, I’ve
written numerous other books, too, not to mention hundreds of arti-
cles for Macworld, TidBITS, and other sites. And sure, I run a publish-
ing company, speak all over the world, have a wife and two kids at
home, and teach tai chi classes. But apart from those minor exceptions
and maybe a dozen others, I’m pretty much a layabout.

However, there’s more than one way to think about laziness. When it
comes to your Mac, a good form of laziness is not wanting to spend
unnecessary time doing something that’s tedious or repetitive. A bad
form of laziness is not bothering to figure out how to save yourself that
effort later on.

I frequently interrupt my work to spend a half hour figuring out how


best to automate a task that might take me a minute to do manually.
But if I save a minute several times every day, that half hour pays for
itself in no time. And from then on, I’m more efficient and happier.
Even if a certain automation technique saves only a second or two,
those seconds add up in a big way over time.

Note: To get a visual sense of how much time you might save in the
long run, see the xkcd comic Is It Worth the Time?.

But saving time isn’t the only reason to automate activities on your
Mac. You’ll also make your work more consistent and accurate. Au-
tomation can prevent small errors that would otherwise trip you up,
and save you the annoyance of looking up forgotten details.

As you read about automation methods, I want you to accept the fact
that you’ll have to spend (not “waste”) time learning, experimenting,
and setting things up, and that this work is going to be a temporary

16
drag on your productivity. Don’t worry about it. The end result will
make you much more productive. Bear in mind, too, that the effort-to-
reward ratio is least favorable at the beginning, as you’re getting to
know the tools and techniques. But as you gain experience, you’ll find
that smaller amounts of effort produce greater rewards.

Your biggest challenge may be figuring out what you can automate and
how. That’s what I want to address in the remainder of this chapter.

Learn the Basic Principle of Automation


I alluded to this in the Introduction, but I want to make sure it’s clear:

For the purposes of this book, automation means finding shortcuts—


easier ways to do the same things you’re already doing regularly.

I use such a broad and inclusive definition because I want you to get in
the habit of looking for easier ways to do things on your Mac without
the psychological barrier of thinking that automation is some intensely
technical process only a computer geek could grasp.

You probably wouldn’t have bought this book if you weren’t already
interested in simple labor-saving shortcuts: if there’s something you do
frequently that requires three clicks and you can come up with a way to
do it with one click instead, you’ve saved yourself some effort. Or
maybe you have a regular task that normally requires a dozen key-
strokes and you can do it with a single menu command instead.

Once you feel confident finding shortcuts like these, you can work your
way up to the more conventional sense of automation—setting up your
Mac to perform complex sequences of useful tasks without any inter-
vention. These could be tasks you would do anyway, or they could be
tasks that would be too complicated, time-consuming, or onerous to
bother doing by hand—tasks such as sorting your incoming email,
monitoring sales figures, or moving files between disks or machines.

Keep in mind, however, that since it takes some time to set up any
automation task, automation saves time only when the activity in
question happens over and over again. Suppose an app has a deeply
17
nested menu command, like Tools > Format > Paragraph > Style >
Quote Level > Increase, and it’s a pain to find it and select it. You could
assign it a keyboard shortcut, but if it’s a command you use only on a
rare occasion, there’s no point. It would take more effort to set up (and
remember) the shortcut than to search for the command manually. On
the other hand, if this is a command you use several times every day,
it’s certainly worth your effort to find a quicker way.

Learn What You Can Automate


Think for a moment about the differences between tasks that can be
described in purely mechanical (or objective) terms compared to tasks
that require human intelligence (or subjectivity). Here are a few
examples to illustrate what I mean.

Mechanical tasks:
• Select all the black pixels in an image.

• Find all capitalized words in italics.

• Type a predefined chunk of text.

• Fill out a web form with my contact information.

• Click your pointer at a spot 50 pixels from the left edge and 120
pixels from the top edge of the frontmost window.

Subjective or creative tasks:


• Select all the flowers in an image.

• Find all allusions to Star Trek in a book.

• Compose a poem.

• Fill out a web form with your opinions on survey questions.

• Click the photo of the most appetizing pastry.

Broadly speaking, mechanical tasks are the ones that most readily lend
themselves to automation. While writing this book, I used automation

18
for things like expanding abbreviations, applying styles, creating
bookmarks, inserting cross-references, and modifying URLs. None of
my automation tools helped me figure out what to write, however.

Your own work undoubtedly includes a mixture of mechanical and


subjective or creative tasks. The more you automate mechanical tasks,
the better you’ll be able to focus on the creative part of your work.

Crucially, you can automate such tasks (and sequences of tasks) even
in cases where variables are involved or decisions are required—
automation need not be blind. For example, you might have a macro (a
structured series of automated actions) that looks at the text on a
certain webpage and, depending on what that text is, takes one of three
actions in response. You might have a command that runs automati-
cally—but only on rainy days, or only if there are fewer than five
messages in your email inbox. You might even have your Mac prompt
you to make a decision manually, or fill in some information, before
proceeding with an automation task.

When trying to determine whether a task is ripe for automation, I like


to ask myself whether it’s something I could explain to my mother how
to do, over the phone. My mom is both intelligent and computer-
literate, although she’s not a technophile. I could say, “Mom, go to this
page in your browser. Now look at the second line from the top. Does it
have a number that’s greater than 100? If so, then open this spread-
sheet, click in the first empty cell in the second column, and type that
number into that cell.” On the other hand, I would not tell my mother,
“Give descriptive names to these 100 technical documents I just
scanned,” because although she might give it her best shot, chances are
close to nil that she and I would choose similar names—and I’d have a
hard time finding a particular document.

Look for Automation Opportunities


Now it’s time for you to start making a list. You can use a text file, the
Notes app on your Mac or iPad, or even (gasp!) a piece of paper, but do
start making a list of tasks you might want to automate right now.

19
As you use your Mac, pay attention to activities that are largely me-
chanical in nature, that you perform more than a few times a day, and
that require more than a single click, keystroke, or menu command.
Jot down what those activities are, and as you read this book, look for
appropriate ways to automate each task. Even if you know for sure that
you want to automate something, it’s not always convenient to drop
everything and do so at the moment you realize it. Having a list helps
you remember what to come back to when you do have time.

In particular, I suggest concentrating on situations in which you might


be able to click less, type faster, use keyboard shortcuts, or set up
hands-off triggers.

Click Less
Although it’s not a perfect measurement of complexity, it’s a conve-
nient way to think about the effort needed to perform common tasks:
How many clicks does it take?

If you click the Finder icon in your Dock to switch to the Finder, click
File > New to open a new window, click on the name of another Mac in
the sidebar, and then click Share Screen to share the screen, that’s a
total of four clicks.

All things being equal, fewer clicks take less effort than more clicks, so
if you can find ways of reducing multiple clicks to a single click (or
perhaps to a keyboard combination), you’ll save effort.

Write it down: When you notice yourself performing a task two or


more times a day, count and write down how many clicks it takes to
complete it, remembering that one click equals a press and release.
(Moving the pointer to a menu command and dragging add complexity
too, but for the sake of this little experiment, you can ignore those
mouse movements.) If an activity also requires keystrokes (such as
entering a username, or searching for a word), count those too—we’ll
come back to extra keystrokes in a moment. Any repetitive activity that
requires more than two clicks could potentially be shortened. The
reason for counting your clicks is so you can roughly prioritize which
tasks may bring you the most gains once automated.

20
What to do: Pretty much any automation I discuss has the potential
to eliminate clicks. Areas that may especially apply, however, are these:

• If you spend too much time launching applications and opening


files, read Automate the Finder.

• If you want to copy and paste multiple items quickly, start with
Supercharge Your Clipboard.

• To automate your mouse, trackpad, or other input device, read


Automate Your Input Devices.

• If you want to switch applications with your voice, try Control Your
Mac with Your Voice, or find other options for quickly getting in and
out of apps in Automate the Finder.

Type Faster
If you don’t already know how to touch-type (that is, type with all ten
fingers, without looking at the keys), learning to do so will probably
save you more time and increase your efficiency more than anything
else in this book. You can find numerous free or inexpensive apps to
help you learn, such as Mavis Beacon Teaches Typing.

But if you’re already a touch typist, you can increase your typing speed
and accuracy even further. For example, I frequently write about an
app called DEVONthink To Go, but I never type out all 16 characters of
that name. I type dttg and my Mac expands that automatically into the
full name. That not only saves time, but also ensures I get all the
capitalization right. I do the same thing with frequently typed names,
addresses, phone numbers, URLs, dates, and other phrases—especially
those that I use more than a few times a day.

Write it down: Consider all the email messages and documents you
wrote in the last 24 hours, and see if you can pick out long names,
phrases, and other text you used repeatedly, such as a company name,
chemical name, or address. Make a note of them.

What to do: Set up shortcuts for yourself to Automate Text Expan-


sion using the tools built into macOS or a third-party utility.

21
Use Keyboard Shortcuts
One premise underlying many of the automation techniques in this
book is:

Using the keyboard has the potential to be considerably faster than


using a mouse (or other pointing device).

To the extent that this is true, it would seem logical to learn (or create)
as many keyboard shortcuts as possible. But I wouldn’t go so far as to
say that keyboard shortcuts are always or even usually faster than
using a pointing device. And let’s not forget the mental effort required
to learn and recall all those shortcuts!

Tip: For a fascinating glimpse into research Apple did in this area in
the late 1980s, read Bruce “Tog” Tognazzini’s articles “Keyboard vs.
The Mouse,” part 1, part 2, and part 3.

Keyboard shortcuts are likely to be superior in certain situations:

• Cases where you’ve memorized a keyboard shortcut so fully that its


application is a matter of muscle memory, often the case with the
most common shortcuts: ⌘-C for Copy, ⌘-X for Cut, ⌘-V for
Paste, ⌘-S for Save, ⌘-W for Close, and ⌘-Q for Quit

• Editing operations in which you can perform a keyboard shortcut


with one hand while selecting text or other elements using your
mouse or other pointing device with the other hand

• Activities that require multiple mouse clicks (refer back to Click


Less)

• Activities that require navigating submenus or searching for a menu


command whose location is unknown

• Repetitive activities (for example, applying a certain menu com-


mand to a dozen different objects, one after the other)

• Actions to which you can assign a mnemonic, multi-key shortcut


sequence, such as ⌘-P-D-F for Save as PDF (see Use Multi-Key

22
Shortcuts in Microsoft Word and Use Multi-Key Shortcuts in Nisus
Writer Pro)

Furthermore, if you are a touch-typist and your work involves mostly


typing (in which case there’s a frequent time penalty for moving one
hand from the keyboard to the pointing device and back), you’re likely
to see greater efficiency improvements from using keyboard shortcuts
than if you’re a hunt-and-peck typist or if your work involves more
mousing than typing.

Write it down: Make a note of tasks you perform several times a day
that require searching for menu commands, as well as those you repeat
two or more times in a row.

What to do: In some cases, you can learn their existing shortcuts (see
Use the Mac’s Built-In Keyboard Shortcuts), but if they don’t have
shortcuts—or you don’t like the built-in shortcuts—you can assign
keyboard shortcuts to them (see Make Your Own Keyboard Shortcut
and Use a Macro Utility).

Set Up Hands-Off Triggers


Clicking less, typing less, and using keyboard shortcuts will form the
core of your automation strategy, but the next step—for certain types
of tasks—is letting them run entirely on their own.

Some automated actions can and should run without any intervention
at specific times or at recurring intervals, such as opening an app or
running a script or macro. As you find applicable cases, you can tell
your Mac to run them according to the calendar and clock. Or, you
might notice some activities that should be triggered automatically in
response to something else, such as restarting or logging in, mounting
a network volume, or changing the contents of a folder. In all these
cases, you can make your life that much easier by setting up automatic
triggers for your automated actions.

Write it down: Make a note whenever you observe yourself engaged


in a pattern of actions—especially those you’ve already automated in

23
some way—such as “every Tuesday morning at 9, I do this” or “as soon
as x happens, I always do y.”

What to do: Read Run Actions Automatically to see whether you


could use a tool built into your Mac to watch for the situation where
your automated task should run and trigger it automatically.

Consider Routine Tasks


I may have given you the impression that automation is best suited
for tasks you perform many times a day. It’s true that the more often
you perform a task, the more you’ll benefit from automating it. But
you might also want to consider automating tasks you perform less
frequently—say, once a week, once a month, or once a quarter.
Do you have to prepare a monthly expense report? A quarterly
summary of customer support email messages? An annual chart of
sales statistics? It may be worth the effort to figure out how to
automate those tasks as well (or portions of them, anyway).
You may not be able to predict how long it will take you to create the
workflow, script, or macro needed for such a task, but in general, I
like to see my automation efforts amortized within a few months. For
example, if a quarterly task takes an hour to do manually, and I can
automate it with an hour’s work, I’ll see that time savings the next
quarter. Spending an entire day automating an annual task that
would otherwise take only 15 minutes makes much less sense—it
could take the rest of your career to recoup that lost time.

Set Yourself Up for Success


I have one last suggestion on the topic of looking for automation
opportunities.

Imagine you’re shopping for an optical character recognition (OCR)


program, a word processor, a photo manager, or a digital audio work-
station app. You’ve narrowed your choices down to two or three
candidates. Which should you buy? All things being equal, I’d pick the
one with the most or best automation capabilities, whether they’re
built in (a macro language, let’s say) or externally driven (for example,
with extensive AppleScript support).

24
Although most apps can be automated by brute force, as it were—
having a macro utility fake a click at certain coordinates in a window,
for instance—that kind of automation is tricky and error-prone. Apps
that expose their functions directly to tools like Automator, Apple-
Script, and LaunchBar make automation much easier. That’s why I talk
glowingly about the automation possibilities in Microsoft Word, Nisus
Writer Pro, DEVONthink, Panorama X, and 1Password. They go out of
their way to make it easy for other apps to communicate with them.

You may also need to request some adjustments to the way other
people send you data in order to facilitate automation. For example,
data you receive in a highly structured form, such as a spreadsheet,
database, or XML file, lends itself well to automation because it’s easy
to instruct a computer to look in a certain field, cell, or key for a piece
of data. Receiving data as a free-form PDF or Word file complicates
automation, because you first have to automate the task of locating just
the needle you need in a fairly large haystack.

These are just a few examples, but my main point is to keep auto-
mation in mind as you make decisions about the apps you use and the
ways you send and receive information. Even if you don’t use those
capabilities now, you may appreciate them in the future.

25
Make Friends with Metadata
Metadata is “data about data”—for example, a song’s data is the
music you hear, but metadata includes the song’s title, composer,
performer, album art, lyrics, and so on—as well as its star rating, if
you gave it one in Music, and any comments you added to its de-
scription. Similarly, files can have metadata such as tags and com-
ments; photos can have titles, ratings, and location information; and
email messages can be marked as sent, read, or junk.
If you get in the habit of adding metadata where it’s appropriate,
you’ll make automation that much easier later on. For example, if you
always mark your favorite songs with 4 or 5 stars, then it’s easy to
make playlists that include only your favorites. Tag your files, and
then it’s easy to use those tags to make smart folders (see Create
and Use Smart Containers). Mark your favorite photos, and then it’s
easy to find them at the end of the year when generating a holiday
card or to show only your favorites to your friends at your college
reunion.
Without question, adding metadata, after the fact, to hundreds or
thousands of existing items is an extraordinary time sink that is
seldom worth the effort. But adding it to new items as you go can
open up interesting automation possibilities in the future.

Pick the Right Tools


I talk about tons of different techniques, features, and apps in this
book. I use most of them myself. But I don’t expect you to go out and
buy every app I mention here, or even one of each type of app. I don’t
expect you to spend the time learning Shortcuts and Automator and
AppleScript and Keyboard Maestro and Nisus Writer Pro macros and
so on. You’re welcome to do that if it sounds like fun (it’s fun for me!),
but for most people, that would be unreasonable and incredibly boring.

Instead, I suggest you read through this book with the idea of picking
out just the handful of techniques and apps that give you the biggest
bang for your buck (or your time). The answer will be different for each
person; it’ll depend on how you use your Mac and what your biggest
sources of annoyance are.
26
I asked myself: If I could pick only one automation tool from this book,
which one would it be? For me, that tool would be Keyboard Maestro
(see Control Your Mac with Keyboard Maestro), because it’s so versa-
tile. It may not be the best launcher or the best clipboard utility or the
best text-expansion tool, but it does a respectable job at all those
tasks—in addition to its crucial core features of creating macros and
letting you assign keyboard shortcuts to commands.

Don’t get me wrong: I’d miss LaunchBar, TextExpander, Nisus Writer


Pro macros, and AppleScript every single day. So, for me, the right
answer is to use a bunch of tools, each for specific purposes. But as
you’re getting started in automation, learning one tool (or a few tools)
more deeply is better than learning many tools only slightly.

Finally, I should caution you not to buy automation apps just because
they sound neat, or because you hope to think up problems for them to
solve. That’s like going to the hardware store and buying a tool without
having anything you need to use it for. (Which, I admit, I’m prone to
do, but I don’t recommend.) Start with the problems you want to solve,
and then find an app or technique that can solve them.

27
Use Built-In Automation
Features
Although it may not be apparent at first glance, macOS contains
dozens of built-in automation features, just waiting for you to make
use of them. In fact, later in this book, I’ll discuss numerous ways to
take advantage of built-in features, such as:

• Use Trackpad and Magic Mouse Gestures

• Use Text Replacement in macOS

• Use Spotlight as a Launcher

• Use Services for Systemwide Shortcuts

• Get Started with Shortcuts

• Get Started with Automator

• Get Started with AppleScript

• Script the Command Line with Shell Scripts

• Manage Incoming Apple Mail with Rules

• Search Faster with Smart Mailboxes

• Log In Faster with iCloud Keychain and Safari Autofill

• Run Backups Automatically with Time Machine

• Run Actions Automatically

But in this chapter, I want to introduce you to a core set of built-in


automation capabilities that don’t fit logically within another topic—or
that don’t go as far as the more capable third-party tools that I discuss
later in this book. Most of these involve things you can do in the Finder
or in System Settings/System Preferences, and they’re among the
easiest ways to start automating your Mac.

28
Use the Mac’s Built-In Keyboard
Shortcuts
Every app that comes with macOS, including the Finder, has keyboard
shortcuts for common commands.

Menu Shortcuts
The best-known type of keyboard shortcut performs a menu command.
You can see the shortcuts right on the menus (Figure 1).

Figure 1: Examples of menu commands with predefined keyboard


shortcuts.

You likely already know that ⌘ means Command; the ⌘ symbol dates
back to the first Mac. Symbols you may be less familiar with represent
three other modifier keys:

• ⌥ means Option

29
• ^ means Control

• ⇧ means Shift

So, if you see a command labeled ^⌘T (File > Add to Sidebar in the
Finder), that means hold down both the Control key and the ⌘ (Com-
mand) key and press T.

The easiest way to learn what keyboard shortcuts are available for
menu commands is to look at the menus as you use them.
Although every app has its own shortcuts, most apps are consistent in
their use of common shortcuts, such as:

• ⌘-A for Select All


• ⌘-B for Bold

• ⌘-C for Copy

• ⌘-D for Duplicate


• ⌘-F for Find
• ⌘-I for Italic
• ⌘-N for New
• ⌘-O for Open
• ⌘-P for Print
• ⌘-Q for Quit
• ⌘-S for Save
• ⌘-U for Underline

• ⌘-V for Paste


• ⌘-W for Close
• ⌘-X for Cut
• ⌘-Z for Undo

• ⌘-, for Settings/Preferences

30
• Return to click the default (highlighted) button in any dialog
• ⌘-. or Esc to cancel the current action

Every Mac user should know these common shortcuts cold, because
they’re useful in nearly every app.

Tip: Try pressing the Option key while displaying a menu. In many
cases, the commands (and their associated shortcuts) change to
reveal hidden options. (This also works with other modifier keys, such
as Shift and Control, but those are used less frequently.)

For many more shortcuts, see Apple’s Mac keyboard shortcuts page.

In addition, you should know a few general principles about menu


commands. These are not hard-and-fast rules, but they’re overall
trends worth being aware of:

• Adding Shift to a shortcut often reverses its meaning. For example,


press ⌘-Tab to switch to the next open application, or ⌘-Shift-Tab
to switch to the previous application. Or, in the Finder, while ⌘-Z is
Undo, ⌘-Shift-Z is Redo.

• Adding Option to a shortcut often applies the command to a broad-


er scope. For example, in the Finder, ⌘-M is Minimize (to minimize
an open Finder window), while ⌘-Option-M is Minimize All (as in
minimize all Finder windows). In TextEdit, ⌘-W is Close (a docu-
ment), while ⌘-Option-W is Close All (open documents).

• Adding multiple modifiers to a shortcut often means “the same


thing, but with different options.” For example, ⌘-V is Paste, but in
most apps, ⌘-Option-Shift-V (or sometimes just ⌘-Shift-V) is
Paste as Plain Text. Similarly, ⌘-Shift-S is often Duplicate (that is,
save the entire document as a duplicate) whereas ⌘-Option-Shift-S
is Save As (that is, save the entire document with a different name).

31
Text Editing Shortcuts
Besides shortcuts for menu commands, macOS has many built-in
shortcuts for working with text. Here are a few you should know:

• Arrow key: Move the insertion point in the direction of the arrow.

• Option-← or Option-→: Move the insertion point left or right by


a word.

• ⌘-← or ⌘-→: Move the insertion point to the beginning or end of


the current line.

• Option-↑ or Option-↓: Move the insertion point to the beginning


or end of the current paragraph.

• ⌘-↑ or ⌘-↓: Move the insertion point to the top or bottom of the
document.

• Shift plus any of the above: Select text from here to the destina-
tion. For example, Option-Shift-→ selects the next word, while
⌘-Shift-← selects to the beginning of the line.

Spend an hour or so practicing these shortcuts and you’ll be able to do


much of your text editing without reaching for a mouse or other
pointing device.

Make Your Own Keyboard Shortcut


If a menu command in one of the apps you use doesn’t already have a
keyboard shortcut—or if it does, but you want to change it to some-
thing different—follow these steps to create your own:

1. Go to System Settings > Keyboard > Keyboard Shortcuts > App


Shortcuts (Ventura or later) or System Preferences > Keyboard >
Shortcuts > App Shortcuts (Monterey or earlier).

2. Click the plus button.

3. In the dialog that appears (Figure 2), select the app you want the
shortcut to work with from the Application pop-up menu. (If you

32
don’t see it listed there, choose Other, navigate to the application,
and click Add.) If you want your shortcut to work in all applications
(or in, say, the pop-up PDF menu that appears in the Print dialog of
all your apps), choose All Applications from the pop-up menu.

Figure 2: Specify the app, menu item, and keyboard shortcut.


(Ventura shown here; it looks quite a bit different in Monterey and
earlier.)

Note: Unfortunately, you can’t assign keyboard shortcuts to com-


mands on menu extras, such as the Wi-Fi menu or the Bluetooth
menu. To create keyboard shortcuts for those commands, you’ll
have to Use a Macro Utility.

4. Enter the menu command—for example Paste, (not the name of the
menu itself—for example, Edit) for which you want to specify a
shortcut in the Menu Title field.

You must get everything—including capitalization, punctuation, and


spaces—exactly correct. If what you type here doesn’t precisely
match what’s on the menu, it won’t work. One exception: If you see

33
an ellipsis (…) at the end of a command, you can type either the sin-
gle ellipsis character (Option-;) or three periods. Either way works.

5. Click in the Keyboard Shortcut field and press the key combination
you want to use. (If another command previously used the shortcut
you enter, your new shortcut will override it.)

6. Click Done (Ventura or later) or Add (Monterey or earlier).

The shortcut should immediately appear next to the menu command


in the app—even if the app is still running—and can be used right
away.

Note: You may occasionally run across an app with a nonstandard


way of implementing menus, in which case custom keyboard short-
cuts don’t work—they don’t show up on the menu, and pressing the
shortcut has no effect. In such cases, your best bet is to Use a Macro
Utility, such as Keyboard Maestro, to assign the shortcut.

Sometimes an app has two or more menu commands with the same
name, located on different menus or submenus. For example, in Mail,
you can find Format > Quote Level > Increase as well as Format >
Indentation > Increase. Likewise, the mailbox names on the Message >
Move to and Message > Copy to submenus are the same. So if you
specify only the menu command name (like Increase), it may not
connect to the right command.

To address this problem, instead of entering just the menu command


name, enter the full path through all the submenus, with -> (that is, a
hyphen followed by a greater-than sign)—and no spaces—between
each step, like so: Format->Quote Level->Increase. This ensures that
the shortcut goes only with the menu command you specify.

Tip: Some apps also have built-in mechanisms for creating keyboard
shortcuts. You can use whichever method you prefer, but an app may
give you more control—for example, Nisus Writer Pro lets you assign
sequences of keystrokes as shortcuts (see Use Multi-Key Shortcuts in
Nisus Writer Pro).

34
If you’re uncertain what keyboard shortcuts might be useful, here are
some ideas to get you started:
• If you frequently assign tags to files, you may want to assign a key-
board shortcut to the Finder’s File > Tags… command. ⌘-T, ⌘-
Shift-T, and ⌘-Option-T are already used by other menu com-
mands, but you can reassign any of them to Tags… if you like.
• How about an All Applications shortcut to open System Settings/
System Preferences (found with a trailing ellipsis […] on the Apple
 menu)?
• Lots of apps have Check for Updates… commands (usually on the
application menu—the one bearing the application’s name), but
that command almost never has a shortcut. If you use it frequently,
it might benefit from an All Applications shortcut.
• Your keyboard may have keys you rarely if ever press (F13–F15,
anyone?), and they can be put to good use. Most of these keys have
preassigned shortcuts, which you can see by looking through the
various categories of System Settings > Keyboard > Keyboard
Shortcuts (Ventura or later) or System Preferences > Keyboard >
Shortcuts (Monterey or earlier), but if you think a key can serve you
better by performing a different action, you should feel completely
free to change it.

Tip: If you’re having trouble remembering all the keyboard shortcuts


for your various apps (either built-in shortcuts or those you created),
try the KeyCue utility, which pops up a context-sensitive list of
shortcuts whenever you press the ⌘ key.

Use and Customize Toolbars


Many Mac apps have a toolbar at the top of each window, and some-
times different windows within the same app display different tool-
bars. For example, Mail has one toolbar for the main viewer window,
another for messages opened in their own window, and a third for the
window used to compose new messages or replies.

35
Each toolbar has buttons and menus for commonly performed tasks,
but if you’re anything like me, you tend to ignore most of what appears
on a toolbar. After all, I don’t need a button for Save or Reply or Bold
as I invariably use keyboard shortcuts for these actions.

While most toolbar controls are simply alternative ways to perform


actions using menu commands or keyboard shortcuts, you shouldn’t
write them off, because:

• A shortcut is a shortcut. If you can click a button on a toolbar more


quickly than you can locate the equivalent menu command or
memorize a keyboard shortcut, this becomes the most efficient way
to perform the activity.

• Even though default toolbars are often pretty dull, you can cus-
tomize almost any toolbar to make it genuinely useful.

To illustrate the second point, consider Preview. Its default toolbar (as
it appears when a PDF is open) is shown in Figure 3.

Figure 3: The default Preview toolbar.

That’s OK, I guess. But I’ve customized mine (Figure 4) to add several
more controls that I nearly always find useful when viewing PDFs:
Scale (which shows me the current zoom percentage and lets me type
in a different number to change the zoom), Previous and Next (for
navigating), and Page (which lets me type a page number to jump
directly to it). Sure, there are other ways to access these features, but in
this specific instance, I find the revised toolbar more efficient.

Figure 4: My customized Preview toolbar, with labels.

In fact, I go a step further and hide the labels (Figure 5), to give
myself a bit more vertical space.

36
Figure 5: My customized toolbar without labels.

To customize a toolbar in any app:

1. Right-click (or Control-click) the toolbar and choose Customize


Toolbar from the contextual menu.

2. Drag icons onto or off of the toolbar, or rearrange them as you like.

3. Click Done.

Note: Some apps, like Nisus Writer Pro, even let you make custom
toolbar items.

You can also choose Icon and Text, Icon Only, or Text Only from the
contextual menu to show or hide icons or labels.

Use macOS Text Substitutions and


Transformations
If you look at the Edit menu in TextEdit, Mail, Messages, Safari, and
numerous other applications that include text editing features, you’ll
see a Substitutions submenu and a Transformations submenu. These
two submenus contain shortcuts for manipulating text. You don’t have
to do anything to make them appear (and you can’t add the commands
in apps that don’t natively support them), but I think everyone should
know about them, because they’re useful yet often overlooked.

Substitutions
As you work with text in supported apps, macOS can automatically
change certain attributes in order to make your text more readable.
When an item on the Edit > Substitutions submenu is checked, it
means that substitution is enabled for that app (only) until you dese-
lect it. (Choose a menu command again to toggle it.)

37
Substitution options are as follows:
• Smart Copy/Paste: If you double-click a word to select it, and
then copy and paste it, a space is added before and/or after if neces-
sary to separate it from the adjacent text. Similarly, if you double-
click a word to select it and then press Delete, extra spaces are
removed. (Smart copy/paste does not occur if you manually drag to
select the word.)

• Smart Quotes: As you type, this feature converts straight quota-


tion marks and apostrophes (" ') into curly quotation marks and
apostrophes (“” ‘’).

• Smart Dashes: As you type, this feature converts two consecutive


hyphens (--) into an em dash (—).

• Smart Links: As you type, this feature converts URLs (including


strings macOS interprets as URLs, even if they don’t start with a
scheme such as http or https) into clickable links.

• Data Detectors: This feature intelligently identifies strings of text


that match patterns like street addresses, dates (even vaguely stated
dates, like “next Tuesday” or “breakfast tomorrow”), phone num-
bers, and flight numbers—and then lets you do appropriate things
with them like add an entry to Contacts, schedule an event in Calen-
dar, look up a location in Maps, track a flight, and so on.
With Data Detectors enabled, if you see a chunk of text that looks
like one of the kinds of data I just mentioned, move your pointer
over it. If Data Detectors considers it to be an appropriate kind of
data, a dotted box will appear around it, with a downward pointing
triangle on the right. Click the triangle to display either a contex-
tual menu with one or more options, or a popover with additional
controls, depending on the type of data.

• Text Replacement: As you type, this feature replaces abbrevia-


tions with user-specified words or phrases, or corrects misspellings.
(This feature is important enough that I talk about it separately; see
Use Text Replacement in macOS.)

38
• Show Substitutions: Select this command to display the Substi-
tutions window (Figure 6), in which you can change any of your
settings for the current app (selecting or deselecting the checkboxes
has the same effect as selecting the corresponding menu command)
or apply substitutions retroactively.

Figure 6: Adjust preferences for substitutions in this window.

I mentioned earlier in the list that substitutions for smart quotes,


smart dashes, smart links, and text replacement occur as you type. In
other words, if you open a document that already contains straight
quotation marks, double hyphens, or plain-text links, macOS does not
convert them automatically. If you want to make such conversions
after the fact, open the Substitutions window, select the desired check-
boxes, and click Replace All (to affect the entire document) or select a
portion of the text and click Replace in Selection.

Transformations
The Transformation submenu contains three commands that change
the case of the selected text:

• Make Upper Case: Converts all lowercase letters to their upper-


case equivalents

• Make Lower Case: Converts all uppercase letters to their lower-


case equivalents

• Capitalize: Converts the first letter of each word in the selected


text to uppercase (regardless of whether that would constitute
proper “title case”)

39
Tip: Do you find yourself changing substitution settings or using
transformations frequently? Why not add a keyboard shortcut to the
relevant commands? See Make Your Own Keyboard Shortcut.

Control Your Mac with Your Voice


Macs have had built-in speech recognition for a long time. Although
this was cool when it first appeared in the mid-1990s, Apple paid little
attention to the feature for many years. It wasn’t until Apple added Siri
to macOS (in 10.12 Sierra) that you could ask your Mac questions and
tell it to do things for you without using any special software, just as
you can on an iOS/iPadOS device, Apple Watch, or Apple TV.

For times when you need to use your voice to perform specific func-
tions outside Siri’s skill set, you can also Use Dictation Commands.
This feature lets you run scripts, press keys, and do other custom
activities—that is, your voice can trigger shortcuts, just like a menu
command or keyboard shortcut.

In ideal conditions, using speech recognition can make it feel like


you’re living in a science-fiction future—things just happen magically
at the sound of your voice. However, it works best in relatively quiet
environments and in settings where talking to your computer won’t
distract or disturb other people. (So, it’s not great for when you’re
working on your MacBook Pro at Starbucks.) And even when it works,
it’s slower for certain tasks than keyboard shortcuts. Still, it’s well
worth becoming acquainted with your Mac’s voice-control tools.

Use Siri
Siri, Apple’s voice-controlled digital assistant, needs little introduction
at this point. Now that it’s part of macOS, it gives you many of the
same informational and control capabilities as its counterparts on
other platforms—plus some capabilities unique to the Mac. Here, I’ll
provide just a quick overview.

Before you can use Siri, you must enable it. You may have turned it on
while installing or upgrading macOS by leaving a checkbox selected,
40
which it is by default. But if not—or if you’re unsure—go to System
Settings > Siri & Spotlight (Ventura or later) or System Preferences >
Siri (Monterey or earlier) and make sure Enable Ask Siri is enabled.
(This appears as Enable Siri on older versions of macOS.) While you’re
there, you can also configure other options, such as which voice,
microphone, and keyboard shortcut Siri should use.

Once Siri is enabled, you can activate it so that it listens for and re-
sponds to vocal commands, in any of the following ways:

• Press the Siri keyboard shortcut. (By default, the shortcut is to hold
down ⌘-Space for about a second. You can change this in System
Settings > Siri & Spotlight (Ventura or later) or System Preferences >
Siri (Monterey or earlier), and I suggest that you do, because other-
wise it’s too similar to the default shortcut for Spotlight, which is to
press ⌘-Space and quickly release both keys.)

• Click the Siri icon in the menu bar.

• Click the Siri Dock icon.

• Say “Siri” or “Hey Siri” on supported Macs. (To turn on this feature,
go to System Settings > Siri & Spotlight [Ventura or later] or System
Preferences > Siri [Monterey or earlier] and enable Listen for “Siri”
or “Hey Siri.”)

• With Voice Control enabled (see the sidebar Voice Control and
Dictation, ahead), say, “Open Siri.”

Siri responds with a couple of beeps and a “What can I help you with?”
window (Figure 7). You can then speak your question or command.

Figure 7: Siri is now ready to listen to you.

41
Siri doesn’t require your commands to follow a preset pattern. Within
reason, you can phrase your requests in everyday language and Siri
(usually) interprets them close to what you would expect.

Tip: Ask Siri “What can I say?” to see a list of examples.

Although Siri can’t offer shortcuts to everything you might want to do


on your Mac, you can start with these suggestions:

• Launch Safari.

• Tell my wife I’m on my way.

• Look up Frank’s address.

• Show me documents I created last week.

• Search the web for coffee grinders.

• Start a FaceTime audio call with Jill.

• Increase screen brightness.

• Play something by the B-52’s.

• What’s today’s weather forecast?

Although I rarely use Siri on my Mac, I find it most useful for com-
mands that would otherwise require multiple steps or digging around
in System Settings/System Preferences, like “What’s my Mac’s serial
number?” or “Enable Bluetooth” or “Show me PDFs with the label
Important.” For more suggestions on how to use Siri on your Mac, see
these articles:

• Apple’s Use Siri on Mac page

• How to Use Siri on the Mac at iMore

• Use Siri on the Mac! A List of Mac Siri Commands at OSXDaily

42
Use Dictation Commands
Macs have a built-in Dictation feature that converts what you speak
into written text. Although that’s an interesting and useful capability—
and arguably a shortcut in some contexts—I don’t cover it in this book.
However, I do want to explain a different feature that helps you accom-
plish tasks with spoken commands: Dictation Commands.

Although Apple no longer uses the term “Dictation Commands,” I use


that in this book to describe speech recognition capabilities built into
macOS that are more primitive than Siri, yet also more flexible in the
sense that you can customize them to do very specific things, for
example simulating keyboard shortcuts or menu commands.

Dictation Commands are part of Voice Control, rather than part of


Dictation. Thus, you can use them only when Voice Control is enabled.
(What’s Voice Control and how does it affect other voice features, like
Siri and Dictation? Read the sidebar ahead for insights.)

43
Voice Control and Dictation
In addition to Siri, your Mac has a feature called Voice Control, which
lets you control your Mac interface with voice commands in a way
that goes far beyond Siri. You can effectively “click” interface ele-
ments with your voice. It also includes context-based automatic text
dictation, enabled whenever the cursor is at a text insertion point.
However, as I mentioned above, macOS also has a separate, stand-
alone Dictation capability that doesn’t offer access to interface-
interaction commands (and which I don’t cover in this book). It’s…
confusing. In the hope of clearing it up slightly, let me outline what
you can manage by voice:
✦ Siri: Siri can activate and deactivate Voice Control. (You can still
use Siri while Voice Control is active, too.)
✦ (Keyboard) Dictation: Standard or “keyboard” Dictation is
available wherever you can type text. It turns speech into text and
also recognizes some punctuation and other characters. You can
turn Dictation on via a key or keyboard shortcut set in System
Settings/System Preferences > Keyboard > Dictation.
✦ Voice Control: Command the interface, dictate text in contextual-
ly appropriate locations, and issue commands to edit text, like
“select paragraph and bold that.”
When Voice Control is on, you can’t use the standard Dictation mode.
But that’s generally OK, because dictation still works as long as the
insertion point is in a location where text can be typed—and com-
mands work there too.
If Voice Control is off, you can tell Siri to enable or disable Dictation,
which is the equivalent of going to System Settings/System Prefer-
ences > Keyboard > Dictation and enabling or disabling Dictation.
However, you can’t use Siri to start dictation mode; for that, you’ll
have to use whatever shortcut is specified in the Shortcut pop-up
menu. However, since commands are part of Voice Control, you can’t
use them in this mode—or even use your voice to edit the text you
entered.
Long story short: it’s generally better to stick with Voice Control than
the standalone Dictation capability.

44
To enable Voice Control, you can either ask Siri to do it (“Enable Voice
Control”) or follow these steps:

In Ventura or later:

1. Go to System Settings > Accessibility > Voice Control.

2. Turn on the Voice Control Switch. A floating window (Figure 8,


left) appears. (It may take a moment to initialize while showing a
series of pulsating dots.)

Voice Control is now enabled and active. (To make it inactive, click
Sleep or say “Go to sleep.”)

Figure 8: This floating window tells you that Voice Control is enabled
and active (left) or inactive (right).

In Monterey or earlier:

1. Go to System Preferences > Accessibility > Voice Control.

2. Enable Voice Control. A floating window (Figure 9, left) appears.

Figure 9: This floating window tells you that Voice Control is en-
abled—though not necessarily active.

Voice Control is now enabled, but not yet active—to make your Mac
begin listening to your commands, click Wake Up or say “Wake up.”

45
(To make it inactive, click Sleep, as in Figure 9, right, or say “Go to
sleep.”)

With Voice Control active, you can speak a command, such as “Search
Spotlight for text” or “Switch to Finder.” (For a partial list of com-
mands you can speak, say, “Show commands.”)

Assuming everything is working correctly, the text of the command you


spoke should appear in a small bubble above the floating window, and
macOS should execute that command.

In addition, if the insertion point is in a document or field that sup-


ports text input, you can dictate text, and macOS inserts it in near-real-
time. (Note, however, that not all apps support this feature well. To see
how it is intended to function, try TextEdit.) To make changes to your
text, you can use spoken commands such as “Select next word,” “Cor-
rect that,” “Delete word,” and many others. To see a list, first select one
or more characters and then say “Show commands.”

Keep reading to learn how to create your own dictation commands.

Note: A site by Sal Soghoian, Voice Control and Omni Automation,


shows you how to use Voice Control in Monterey 12.3 and later with
Omni Group apps.

Create Your Own Dictation Commands


macOS includes oodles of base commands, many of which can be
further extended. For example, you can insert the name of any menu in
the “Click menu name menu” command, and the name of any running
app in the “Quit app name” command.

You can even add your own commands. Custom commands can open
files or apps, paste text or other data, perform keyboard shortcuts, or
run Automator workflows (which, in turn, can include AppleScript,
JavaScript, and shell script code)—see Get Started with Automator.

46
To create your own Dictation Commands, follow these steps:

1. Go to System Settings/System Preferences > Accessibility > Voice


Control.

2. Click Commands.

3. Click the plus button.

4. In the “When I say” field, enter the word(s) you want your Mac to
respond to.

5. From the “While using” pop-up menu, choose Any Application if


you want your command to work everywhere, or choose a specific
app to restrict the command to that app.

6. From the Perform pop-up menu, choose the action you want to
perform in response to the command, such as Open Finder Items,
Open URL, Press Keyboard Shortcut, or Run Workflow, and select
or enter the requested details.

7. Repeat the above steps as desired to add more commands.

8. Click Done.

Now your custom commands should work whenever Voice Control is


active.

Update Apple and Mac App Store


Software Automatically
All updates to Apple apps that aren’t included as part of macOS, such
as Pages and Final Cut Pro, are delivered through the App Store app.
And, of course, you can update all the third-party apps you’ve bought
from the App Store at the same time.

To check for app updates manually, you open the App Store app and
click Updates. Then, to update a single application, click the Update
button next to it. (In some cases, Apple groups multiple software
updates together; click the More link to see details on each one.) To

47
update all the listed applications at once, click Update All. Enter your
Apple ID and password if prompted to do so, and click Sign In. The
App Store downloads and installs the updates.

To update core macOS components manually, you can open System


Settings > General > Software Update (Ventura or later) or System
Preferences > Software Update (Monterey or earlier) and, if any
updates appear, click Update Now (or Upgrade Now). This may require
restarting your Mac.

But this is a book about automation, so we’re more interested in how to


make this happen automatically! You can have macOS merely inform
you of future updates or download (and optionally install) them as
soon as they appear.

Because software updates often fix crucial bugs and add important
features, I prefer to learn about them (and download them) as soon as
possible. I don’t necessarily install updates as soon as they appear,
because I might be busy with things that can’t be interrupted—and I
want to know when something might be about to change—but some
people may choose to do so as the fastest and most hands-off method.
Still others never want to be interrupted with alerts about new soft-
ware and dislike the idea of anything downloading behind their backs,
or they need to keep an eye on a bandwidth usage cap. You can decide
where you stand and configure your Mac accordingly.

Configure Software Updates


Follow these steps to configure software updates:

1. In Ventura or later, go to System Settings > General > Software


Update (Figure 10); in Monterey or earlier, go to System Prefer-
ences > Software Update (Figure 11). macOS checks for updates,
and any available updates appear at the top of the pane. To apply
them, click Update Now, Apply Now, or Restart Now—the wording
may vary depending on the nature of the available updates.

48
Figure 10: Configure automatic updates for Ventura or later in this
settings pane.

Figure 11: Configure automatic updates for Monterey or earlier in


this preference pane.

2. To turn on all automatic updates in Monterey or earlier, check


“Automatically keep my Mac up to date.” Or, to specify which
updates you want macOS to install automatically, click the Info
icon (Ventura or later) or click Advanced (Monterey or earlier). A
dialog (Figure 12 or Figure 13) appears.

49
Figure 12: Select which types of automatic updates you want here
(Ventura or later).

Figure 13: Select which types of automatic updates you want here
(Monterey or earlier).

3. “Check for updates” is enabled by default. Disable it to stop auto-


matic checking. (In some situations, you must enter your password
after changing this setting.)

50
If it’s enabled, you can also choose to enable any or all of:

‣ Download new updates when available, which not only notifies


you of updates but also downloads them for you so you can
install them as soon as you’re ready. (In the notification, click
Install to install immediately; click Later and choose Try in an
Hour, Try Tonight, or Remind Me Tomorrow from the pop-up
menu to “snooze” the reminder; or click the notification itself to
open the App Store and see which updates are available.)

‣ Install macOS updates, which downloads and installs updates to


macOS itself—for example, macOS 13.x—and asks you to restart
your Mac. (You may be prompted for your password if you
change this checkbox.)

‣ Install application/app updates from the App Store, which


silently updates installed apps from the App Store, except those
requiring a restart or other interaction.

Note: For additional App Store update preferences, open the App
Store app and choose App Store > Settings/Preferences.

‣ Install Security Responses and system files (Ventura or later) or


Install system data files and security updates (Monterey or
earlier), which installs these essential updates without prompt-
ing you. (In Monterey and earlier, this may occur only after
they’ve been available in the App Store for three days.)

You’re welcome to select any or all of these options. I used to prefer—


and recommend to others—selecting all of them except “Install macOS
updates,” on the theory that it’s better to wait a few days for system
updates to confirm that other users aren’t experiencing any major
problems. But Apple’s track record has shown that leaving everything
selected is fine. The bonus is installing bug fixes sooner than later.

51
Tip: If your Mac supports Power Nap (see What is Power Nap on
Mac?) and you enable it in the System Settings > Battery > Options
(Ventura or later) or System Preferences > Energy Saver (Monterey
or earlier), your Mac also downloads updates from the App Store
when it’s asleep—as long as it’s plugged in to AC power.

Update Non-Mac App Store Software


Automatically
Software that doesn’t come from Apple or the App Store must use a
separate update mechanism. Happily, most modern applications
contain some sort of update feature. Unhappily, they don’t all work the
same way. Some check for updates every time they’re launched, or on a
fixed schedule, while others check only on demand; of those that do
check automatically, not all have this feature turned on initially. Some
programs can download and install new versions of themselves auto-
matically, while others download a disk image and expect you to open
it and run the installer yourself; still others do nothing but open a
webpage with links to updates you can download manually.

In an ideal world, updates would require no intervention other than a


click or two to confirm that you’re aware of, and approve of, the instal-
lation; everything else would happen automagically. Because many
applications still lack that level of automation, though, you may have to
perform some extra steps.

For now, do the following. Whenever you download and install a new
app that doesn’t come from the App Store, check its preferences to see
whether there’s an Automatically Check for Updates (or similar)
feature. If so, be sure to turn it on! If you can choose how often to
check, choose the most frequent option. You might also do the same
for your most frequently used apps the next time you open them.

52
Tip: Don’t just check standalone apps for an Automatically Check for
Updates feature; also look for this option in preference panes, status
menus, Mail plugins, and other such software. The wording of the
command may vary, but such commands (Figure 14) usually appear
in the application menu, the Help menu, or the Preferences window.

Figure 14: In some applications, such as Transmit (left), the Check


for Updates command appears in the application menu—the one with
the same name as the application. In others, such as Excel (right), it
appears in the Help menu. Wording may also differ between apps.

Work with Rule-Based Searches


When you put together a rule-based search—whether it’s a smart folder
in the Finder or a smart playlist in Music—you let your Mac do the
tedious work of identifying items (files, messages, songs, and so on)
that are of interest to you. This saves you the time and effort of manu-
ally looking through many potential matches for the right thing. Define
the search once, and even if it’s extremely complex, you can repeat it
whenever you want with just one click—a classic automation shortcut.
Advanced searches in the Finder, rules and smart mailboxes in Mail,
smart playlists in Music, and many other environments—including
some in third-party apps such as Hazel (see Organize Files with Hazel)
and DEVONthink—use a nearly identical interface for finding things
based on a series of conditions. Once you’ve learned how to construct
one of these rule-based searches in one place, you can recycle that

53
knowledge, with minor variations, in lots of different places, many of
which I cover in the next topic (Create and Use Smart Containers).

Before we begin, let me clarify some basic concepts:

• Condition: A condition (sometimes called a criterion) is any piece


of information used to identify an item you’re searching for—a word
in a filename, a modification date, the sender of an email message,
and so on.

• Multiple conditions: A search can have more than one condition,


and these can be used together or individually.

For example, I can search for all files that both (a) contain the word
“book” and (b) were modified within the last week, in which case
files that have one of those attributes but not the other wouldn’t
show up in such a search. This is known as an All search, because all
the conditions must match.

Or I can search for files that either contain the word “book” or were
modified with the last week, which would match a much larger
number of files. This is known as an Any search, because matching
any one of the conditions is enough for a positive result.

• Nested conditions: Most rule-based search environments (sadly,


not Mail’s rules) have a hidden capability to simulate Boolean
(AND/OR/NOT) logic by grouping conditions in Any, All, and None
categories. For example, I can search for files that contain Any of
Jack or Jill, or All (i.e., both) of Cindy and Sandy, but None of
Thomas. In other words, written in Boolean notation it would look
like (Jack OR Jill) OR (Cindy AND Sandy) AND NOT Thomas. You
can use this technique to devise highly detailed and specific search-
es.

I’ll use the Finder to illustrate how to set up a rule-based search; just
remember, you’ll follow the same steps wherever you use this tech-
nique.

54
To perform a rule-based search in the Finder:

1. Press ⌘-F (for Find). The insertion point jumps to the Search field
in the upper-right corner.

2. Type some text in that field, such as book. The window begins filling
with all the files on your Mac containing that text. Press Return to
search for the text you’ve entered in the contents of any file, or
select a narrower category (such as “Name matches: book”) from
the pop-up menu that appears.

Your search now has its first condition, such as “must contain the
text book,” but you can change that later.

3. Optionally change the search scope by clicking a folder name, This


Mac, All, or another term on the left side of the search bar.

4. Click the plus button next to the Save button (below the Search
field). A new row appears (Figure 15).

Figure 15: Click the plus button to see a new condition row.

5. From the leftmost pop-up menu in this new row, choose an at-
tribute to search for, such as Kind, Name, or Contents.

Depending on what attribute you choose, the rest of the row may
change. For example, if the attribute is Kind, then the only thing left
in the row is a single pop-up menu you can use to pick a kind. But if
you choose [Created Date], you see additional pop-up menus and/
or fields (Figure 16), where you can specify, for example, is
[Within Last] [12] [Days].

Figure 16: As you change attributes, the rest of the row adjusts.

With each choice you make, the rest of the row adjusts accordingly.
For example, if you chose [Created Date] followed by is [exactly],

55
then the remainder of the row changes to show only a date field
where you can enter a single, specific date.

Use the pop-up menus and fields to specify your entire condition.

Tip: In Finder searches, you can add many attributes to that leftmost
pop-up menu. To learn more, read my Macworld article Six quick
Spotlight tips, which is from 2013, but remains largely accurate.

6. To add a second condition that will narrow the search, click the plus
button at the right of the current condition and repeat step 4.

Note: In most apps that use search rules like this, a pop-up menu
with Any, All, and sometimes None appears above the conditions
either all the time (or as soon as you add a second condition). In the
absence of an explicit menu, assume it’s an All search—that is, all
conditions must be satisfied for an item to match.

7. To add a nested condition or group of conditions with its own Any/


All/None specification, hold down the Option key and click the
ellipsis button, which replaces the plus button. A new section
(Figure 17) appears. Choose Any, All, or None from the pop-up
menu, fill in the condition just as in step 5, and optionally add more
conditions as in step 6. Repeat this step (at any level of the rule) to
add still more nested conditions.

Figure 17: When you hold down Option and click the ellipsis
button, your search options expand considerably.

8. Recall from step 2 that in Finder searches, whatever you initially


typed into the Search field remains part of the search. If you want to
remove it (to search only for the detailed conditions you added
later), select the text in the Search box and press Delete.

56
That may seem like a lot of steps, but most of them are optional—and
once you’ve done a few searches this way, the process will seem both
quick and obvious. With this technique under your belt, you can now
move on to create smart containers.

Note: When you construct rules in Mail (see Manage Incoming Apple
Mail with Rules), Hazel (see Organize Files with Hazel), and other
such apps, the search conditions are only part of the equation—you
then go through a similar procedure to specify what action(s) should
occur when an item matches.

Create and Use Smart Containers


The Finder has smart folders. Music has smart playlists. Mail has
smart mailboxes. Photos has smart albums. Contacts has smart
groups. I refer to all these (and similar constructions in other apps)
collectively as smart containers. Although they may look like folders or
mailboxes or whatever, they’re really just saved searches. You con-
struct search rules as described previously, click a button to save the
search, and give it a name. Then…hey, presto! Select that smart con-
tainer whenever you want to display an up-to-date list of all the items
that currently match your search.

Here’s a quick overview of how to create and use smart containers in


several popular apps:

• Smart folders (Finder): Choose File > New Smart Folder (⌘-
Option-N), or create a search rule as described in the previous topic.
When you’re finished, click the Save button in the search bar. Give
the smart folder a name, choose a location (the default is ~/Library/
Saved Searches), and for maximum convenience, also check Add to
Sidebar. Click Save. Thereafter, select that item in a Finder
window’s sidebar (or open it wherever you saved it) to show
currently matching items.

• Smart folders (Notes): Notes in Monterey and later offers smart


folders, too. They aren’t as flexible as those in the Finder, but they

57
will gain additional power in macOS Ventura. For now, they rely on
tags, which you can type in any note to categorize it—just type a
word preceded by a pound (#) sign, such as #cooking. Having added
tags to some of your notes, you can then create a smart folder that
shows only notes with specified tags. To do this, choose File > New
Smart Folder, type a name for your smart rule, and then select one
or more tags. Click OK. The smart folder appears in the sidebar on
the left side of the Notes window.

• Smart playlists (Music): In Music, choose File > New > Smart
Playlist (⌘-Option-N). Fill in the desired conditions, and optionally
select the checkboxes to limit the playlist to a certain number of
tracks, match only checked items, or use live updating.

(I recommend live updating; without it, the smart playlist will


always show whatever it happens to match at the time you created
it, unless you manually update it by right-clicking or Control-click-
ing the smart playlist and choosing Update Smart Playlist from the
menu. However, live updating may make Music slower to respond;
if so, you’ll have to decide which annoyance you’d rather endure.)

To view and play the items in that playlist, select Playlists (if the
sidebar isn’t already visible) and then select the smart playlist.

• Smart mailboxes (Mail): In Mail, choose Mailbox > New Smart


Mailbox. Fill in the conditions you want to use, bearing in mind that
Mail does not support nested Any/All/None conditions. Optionally
select Include Messages from Trash or Include Messages from Sent,
as you prefer. Give the smart mailbox a name and click OK. Smart
mailboxes appear in their own category in Mail’s sidebar—if it’s not
visible, choose View > Show Mailbox List.

• Smart groups (Contacts): In Contacts, choose File > New Smart


Group (⌘-Option-N). Fill in the conditions that you want to use,
name the smart group, and click OK. Smart groups appear with
your other groups (if any) in the sidebar. To view all the contacts in
a smart group, select it.

58
Note: To edit an existing smart playlist, mailbox, album, or group,
right-click (or Control-click) it and choose Edit Smart Container Type
from the contextual menu.

If you’re still not sure how a smart container might serve as a useful
shortcut, consider these ideas:

• A smart folder that shows all the files created or modified in the
preceding calendar year that also have the tag tax info, regardless
of the files’ locations. Handy for tax time!

• A smart mailbox that shows you all the messages you sent or re-
ceived in the last month that mention a certain family member,
regardless of where those messages are filed.

• A smart playlist in Music that includes all purchased music tracks


that you haven’t yet listened to at least five times. Make sure you get
to know all your newly purchased music!

• A smart group in Contacts that contains all the other parents of kids
in the same class as your child. You can do this by having a smart
group [Note] [Contains] [school] and then putting the word
“school” in the Note field of each parent’s contact. As the class
composition changes, you can add or remove “school” from records,
and the smart group updates automatically.

Deal with the Mac’s Evolving Security


Features
With each new version of macOS, Apple adds or enhances security
features. Some of these security changes aim to prevent malware from
hijacking your Mac, stealing your data, or displaying annoying ads.
Others are intended to thwart hackers who might try to gain access to
your computer using a network or via apps that might send private
information about you back to the developer without your consent. I
think most of us would agree that improved security and privacy are
excellent goals.

59
Unfortunately, Apple’s go-to solution for any perceived security or
privacy threat is to display an alert with limited details, letting you
decide whether or not you trust the app to perform a given activity.
That can result in a long series of alerts. Apple provides too little
information to judge the safety of what it’s asked us to approve. So
most of us simply end up agreeing to all of them so we can get back to
work. (In some cases, we must do more then just click a button, but it’s
unclear how the extra steps to enable certain kinds of apps to do their
thing makes our lives better.)

The more recent your version of macOS, the more of these alerts you’re
likely to see, and it’s particularly bad as you launch apps for the first
time. For better or worse, the types of automation activities covered in
this book are especially likely to prompt these alerts, because they’re
also the sorts of things that malicious software might want to do
behind your back.

So, before leaving this chapter about the Mac’s built-in automation
features, I wanted to be sure to tell you about security features that can
interfere with automation—whether you’re using Apple’s software or
third-party apps.

Accessibility Access
Apps that manipulate the user interface in one way or another to
provide system enhancements and extra features may need you to
approve them to use Apple’s accessibility features. Examples include
launchers, macro utilities, text-expansion utilities, scripting tools, and
AppleScripts that use GUI scripting—among many others. Even apps
that come with macOS itself (such as Script Editor) may fall into this
category, depending on how you use them.

When one of these apps needs your permission to run, you’ll see an
alert like the one in Figure 18.

60
Figure 18: To grant an app permission to control parts of your Mac’s
user interface, click Open System Settings/System Preferences. To
refuse, click Deny.

You can’t grant this type of access right in the alert dialog. Instead, do
the following:

• Ventura or later: Go to System Settings > Privacy & Security >


Accessibility (Figure 19). Turn on the switches corresponding to
the app or apps to which you want to grant access, and authenticate
when prompted.

• Monterey or earlier: Go to System Preferences > Security &


Privacy > Privacy > Accessibility. Click the lock icon at the
bottom, and either use Touch ID on an enabled Mac, or enter your
password and click Unlock. Then select the checkbox(es) for the
app(s) to which you want to grant access.

61
Figure 19: Grant accessibility access to apps here.

Automation Access
Another category is automation access. To ask your permission, an app
displays a dialog like the one in Figure 20.

62
Figure 20: This app is asking you for automation access.

You may notice that this dialog specifies the name of an app (in this
case, Finder). Any app or utility that requests automation access must
do so individually for each app it wants to control. So you may see this
alert multiple times per app. To grant automation access immediately,
just click OK in the alert. Alternatively—or if you change your mind
about an app later—do the following:

• Ventura or later: System Settings > Privacy & Security > Au-
tomation (Figure 21). Click the disclosure arrow next to a utility,
and then turn the switch on or off for each app that utility wants to
control via automation access.

• Monterey or earlier: Go to System Preferences > Security &


Privacy > Privacy > Automation and check or uncheck the app(s)
you permit the listed utilities to control.

63
Figure 21: For each app that has requested automation access,
enable the apps you allow it to control.

Full Disk Access


Another privacy category is Full Disk Access. This isn’t merely about
manipulating the user interface or automating actions within an app;
this type of access gives the requesting app permission to read and
modify files of a potentially sensitive nature (such as your email and
messages). That may sound scary, but all it does is place an extra
barrier between the bad guys (especially malware) and your important
data. It’s entirely appropriate—indeed, necessary—for you to grant
certain types of software access to this data. One example is a Mail
plugin/extension, such as SpamSieve, which needs access to your
email in order to do its job.

If an app or utility needs access to your files, it will generally notify you
in some way. There’s no single systemwide alert for this purpose, but
you may see either a standalone dialog or a message somewhere within
the app asking for access.

64
Like Accessibility Access, Full Disk Access requires you to manually
grant permission. If an app needs this control, do the following:

• Ventura or later: Go to System Settings > Privacy & Security >


Full Disk Access (Figure 22). If the app already appears in the list
on the right, turn on its switch. If not, click the plus button, navi-
gate to the app, select it, and click Open.

• Monterey or earlier: Go to System Preferences > Security &


Privacy > Privacy > Full Disk Access. If the app already appears in
the list on the right, check the box next to it. If not, click the plus
button, navigate to the app, select it, and click Open.

Tip: Navigating to apps can be surprisingly time consuming. Use the


Open dialog’s search field to enter the name of the app to have it
appear almost instantly.

Figure 22: The Full Disk Access category enables apps to access
data anywhere on your disk.

Some apps that need Full Disk Access do not notify you. Because of
this, they can be completely nonfunctional until you figure out that you

65
need to follow the above steps—and, more confusingly, figure out
where to select the precise app file that requires access.

One such app is Terminal. Some operations that use the sudo com-
mand (such as changing file ownership with chmod) work only if you’ve
added Terminal to the list of apps in Full Disk Access. (See this discus-
sion for more details.) Oh, and if you’re using Terminal to change
ownership on a remote Mac via SSH, you’ll need to choose Go > Go to
Folder in the Finder, enter /usr/sbin, and then drag the SSH daemon
(/usr/sbin/sshd) to the Full Disk Access list too.

Safari may also require Full Disk Access to open locally stored HTML
files that you want to preview in the browser. If you encounter this, I
recommend enabling Full Disk Access only while you’re previewing
locally stored HTML files, such as previewing webpages you’re modify-
ing, and then disabling it when done to avoid opening a web-based
security hole.

Files and Folders


In recent versions of macOS, there are even more situations in which
apps have to ask permission to access files, beyond those covered by
Full Disk Access. Basically, if an app wants to access a file it didn’t
create—without any manual action on your part such as double-click-
ing or navigating in an Open or Save dialog—it’s going to throw up a
dialog, no matter where the file is (even if it’s in the Trash).

You can manage apps to which you’ve granted file access permission in
System Settings > Privacy & Security > Files and Folders (Ventura or
later) or System Preferences > Security & Privacy > Privacy > Files and
Folders (Monterey or earlier).

Keystroke Receiving
If an app needs to watch for keys being pressed—as is the case for
utilities like Keyboard Maestro, which lets you assign keyboard short-
cuts to arbitrary actions—you must explicitly allow that access. If a
newly installed app needs this capability, it will prompt you (Figure
23).

66
Figure 23: This app wants to be able to receive keystrokes.

Do the following:

• Ventura or later: Go to System Settings > Privacy & Security >


Input Monitoring. Then turn on the switch next to each app you
authorize to watch your keyboard. After the first one, authenticate
when prompted to do so.

• Monterey or earlier: Go to System Preferences > Security &


Privacy > Input Monitoring. Click the lock icon and enter your
password. Then select the checkbox next to each app you authorize
to watch your keyboard.

Screen Recording
The term “screen recording” evokes capturing a movie of what happens
on your screen, and that is indeed something you need to grant per-
mission for explicitly. However, Apple uses the term more broadly to
identify apps that can actively watch what happens anywhere on the
screen, identify controls and other elements visually, and take action
on them, even if no recording is taking place. Apps such as Bartender,
BetterTouchTool, DEVONthink, and Keyboard Maestro rely on these
capabilities for their automation features.

If an app requires screen recording access to do its job, it presents an


alert (Figure 24).

67
Figure 24: This app needs access to your Mac’s screen recording
capability.

To grant this access or manage which apps already have access to your
screen in this way, go to System Settings > Privacy & Security > Screen
Recording (Ventura or later) or System Preferences > Security &
Privacy > Privacy > Screen Recording (Monterey or earlier).

68
Automate Your Input
Devices
We’ve talked about your keyboard already, and we return to it in
several future chapters. But I want to take a moment to talk about
other input devices, such as the one you use to move your pointer, as
well as game controllers and other special-use input devices.

Remember when every Mac came with a one-button mouse? Now


buttonless multi-touch trackpads and Magic Mice (with no visible
buttons) are de rigueur, but it’s still easy to find third-party mice,
trackballs, and other input devices with numerous configurable but-
tons, wheels, and other controls. Even Apple’s minimalist pointing
devices can be configured to do special things with gestures and
combinations of modifier keys and clicks.

Every extra button or control on an input device can be put to some


good use. Although you need not use anything other than a simple
keyboard and a pointing device with a single button, you may—
depending on your needs, tasks, and disposition—find it easier and
quicker to do certain tasks via a dedicated button or knob than with an
obscure menu command or keyboard shortcut.

Would you indulge me in a brief story?

I used to manage software development for Kensington, a computer


accessories company. One of our products was a four-button trackball
called Expert Mouse (or, in some variants, Turbo Mouse). I shared a
large office we called the Mouse Lab with three other people—Cris,
Debra, and Don. One afternoon when we all should have been busy
with more productive tasks, we made up a game that, while goofy,
illustrates the kind of thing you can do with a bit of clever automation
and a few extra buttons on your input device.

We each started by making rules in Outlook (our email program) to


play unique sounds whenever we received an email message from one

69
another. For example, when I received a message from Don, my
computer went Zing! but when Debra sent me a message, it went Pop!
Everyone had a custom sound for each other person in the room.

Next, we configured MouseWorks (the software, since superseded by


KensingtonWorks, used to control our trackballs) so that each of the
three extra buttons—besides the one used for a regular click—sent one
of the others a blank email message.

Is your head spinning yet? Well, here’s the result of our labors. I click
button #2 on my trackball and Don’s computer makes a Crack! sound.
Don clicks button #3 on his trackball and Debra’s computer makes a
Ping! sound. Cris clicks button #4 on his trackball and my computer
makes an Oof! sound. And so on. So we spent half the day zapping each
other with our trackball buttons. You had to be there, I guess, but it
was hilarious, like a virtual pillow fight.

That’s not a useful example of automating input devices, I admit. But


perhaps it will inspire you to think up customizations that will make
you more productive.

Use Trackpad and Magic Mouse


Gestures
If you have a Mac laptop with a built-in trackpad, or a standalone
Magic Trackpad, you have at your disposal a device that supports not
just moving the pointer and clicking, but also scrolling, switching apps,
displaying contextual menus, zooming, and numerous other actions by
way of gestures such as swiping, pinching, and tapping (with one or
more fingers). Apple’s Magic Mouse also has a multitouch-capable top
surface with support for many (but not quite all) of the same actions.

You must configure your trackpad or mouse with the gestures you
want to use—that’s the easy part. The harder part is training your
fingers to perform these gestures until they become second nature.

70
To set up your multitouch trackpad or Magic Mouse:

1. Open the Trackpad (Figure 25) or Mouse pane of System Settings/


System Preferences, depending on which device you’re using.

Figure 25: The Trackpad pane of System Preferences has numerous


options for configuring taps and gestures.

2. In each view (Point & Click, More Gestures, and—for trackpads


only—Scroll & Zoom), hover over a gesture to display a video or
animation demonstrating how it works.

3. To enable a gesture in Ventura or later, use the pop-up menu to


choose anything other than Off; in Monterey or earlier, select its
checkbox.

4. Some gestures have multiple options—use the pop-up menu for the
gesture to specify your preference. For example, in the More Ges-
tures view of the Trackpad pane, the “Swipe between full-screen
applications” gesture can be performed by swiping left or right with
either three fingers or four fingers.

71
5. Practice the gestures you’ve just configured! You may find it helpful
to create a little cheat sheet with the gestures and settings you’ve
chosen (e.g., “4 L/R to switch apps”) until you’ve memorized them.

As you use gestures, you’ll find them increasingly natural—and it will


drive you crazy to use a Mac with different settings!

Use BetterTouchTool
Unfortunately, Apple’s settings/preference panes offer no way to
assign custom actions to trackpad and mouse gestures—you can’t, say,
swipe left with three fingers to run a script. If you want to do that sort
of thing, you need an incredibly powerful and customizable app called
BetterTouchTool, which lets you configure almost any combination or
sequence of taps, clicks, and swipes (with one or more fingers) to
perform keyboard shortcuts, menu commands, and a wide variety of
other actions.

BetterTouchTool (Figure 26) has such a huge variety of features that


it would take dozens of pages even to hit all the main points. It’s an app
that certainly rewards exploration and experimentation, however.

Figure 26: Trackpad gestures configured in BetterTouchTool.

72
The usual workflow is to add or select an app (or All Apps) in the
sidebar first, which specifies where the gestures you set up will oper-
ate. (While you can use the same gesture to mean different things in
different apps, I find that excessively confusing.) Next, select an input
device using the pop-up menu at the top of the window—that can be a
mouse, trackpad, keyboard, Touch Bar—or even a Siri Remote. Then
you add a gesture for that device, such as “Pinch With Thumb And 2
Fingers.” Finally, you specify what should happen when you perform
that gesture in that context.

Beyond that, here are some useful things to know:

• Among the many gestures you can use are taps, swipes, pinches,
and force presses with various numbers of fingers; sequences of
taps; sequences of keystrokes; freeform gestures you “draw” your-
self; and moving your pointer to a particular corner of the screen.

• The activities BetterTouchTool can trigger when your chosen


gesture is performed include nearly anything you can think of,
which includes menu commands, keyboard shortcuts, mouse clicks,
AppleScripts, Automator workflows, shell scripts, window manipu-
lation, and switching apps, as well as many, many others.

• A gesture can also trigger a sequence of actions. Which is to say:


BetterTouchTool can function as a macro utility, somewhat along
the lines of Keyboard Maestro. (See Use a Macro Utility.)

If that sounds intriguing, you can download a 45-day free trial of the
app to play with before making a purchase commitment.

Customize Your Touch Bar


Do you have a MacBook Pro with a Touch Bar? If so, you have yet
another customizable input device at your disposal. I mentioned above
that BetterTouchTool enables you to add Touch Bar gestures. But even
without any extra software, you can tweak your Touch Bar’s behavior
to make it more useful.

73
To customize your Touch Bar:

1. In Ventura or later, go to System Settings > Keyboard and click


Touch Bar Settings (Figure 28); in Monterey or earlier, go to
System Preferences > Keyboard > Keyboard.

Figure 27: You can customize Touch Bar behavior here in Ventura or
later; in Monterey and earlier, controls are a bit different.

2. From the “Touch Bar shows” pop-up menu, choose one of the
following (your options may vary depending on your version of
macOS):

‣ App Controls: This is the default setting, which shows different


context-dependent controls as appropriate for the frontmost app.

Note: With App Controls, Quick Actions, or Spaces selected, you can
optionally enable Show Control Strip to display the Control Strip, an
expandable set of icons on the Touch Bar’s right-hand side for things
like brightness, volume, and search.

‣ Expanded Control Strip: This view shows all the icons (13 by
default) on the Control Strip all the time, as opposed to just when
you expand the strip when App Controls, Quick Actions, or
Spaces is selected.

‣ F1, F2, etc. Keys: This setting displays the function keys that
appear on non–Touch Bar Mac laptops. So, if you’re not much of
74
a Touch Bar fan, you might use this to approximate what your
keyboard would be like without one.

‣ Quick Actions: Quick Actions are Automator actions you create


(or download) to perform specific tasks; I say more about these
in Create Your Own Service. You can display your Quick Actions
pm the Touch Bar with this setting. (To configure which Quick
Actions appear, go to System Preferences > Extensions > Touch
Bar and select or deselect items in the list there.)

‣ Spaces: Choose this option to display buttons on the Touch Bar


representing each Space you’ve set up on your Mac, for easy
switching.

3. Regardless of your setting from the previous step, you can configure
the Touch Bar to show a different set of options when you hold
down the Fn key: from the “Press and hold fn key to” pop-up menu,
choose one of the other options listed above.

4. In Ventura or later, you can also enable “Show typing suggestions”


to display suggested words on the Touch Bar to complete what
you’ve typed, much like the QuickType bar on an iPhone or iPad.

5. You may want to customize which icons the Control Strip includes.
To do this, click Customize Control Strip. Then drag icons from your
screen all the way down onto your Touch Bar. Then click Done.
Note that if the regular Control Strip is visible when you do this, you
can customize only the four icons it displays; to customize the
expanded Control Strip, first switch to a setting that displays it.

Save Clicks with Third-Party Input


Devices
In Apple’s design aesthetic for pointing devices, even a single visible
button is considered excessive. But some people like having lots of
buttons, and if you find it easier to remember “click the second button
from the left” than “swipe down with three fingers” do perform a
particular action, a third-party device might be just what you need.
75
During the time I worked at Kensington, we had a trackball model
(Turbo Mouse Pro) with 11 buttons and a trackpad (WebRacer) with 22
buttons—all programmable! Those models have been discontinued,
but companies like Kensington, Logitech, and Microsoft still sell mice
and trackballs with multiple buttons that you can customize. In some
cases, you can also customize scroll wheels and other controls.

An obvious use for an extra button is to perform a double-click. (Recall


that, all things being equal, less clicking is preferable.) If you have your
hand on your pointing device most of the time anyway, perhaps a
finger naturally falls on an “extra” button that can serve this purpose.
You might also use buttons for frequent operations such as Undo, Cut,
Copy, Paste, switching apps, and so on.

Most third-party input devices come with software that lets you cus-
tomize the controls. Kensington trackballs come with Kensington-
Works, Logitech pointing devices come with Logitech Control Center,
and Microsoft mice…somehow, even in 2018, include software only for
Windows. But no matter, you can still customize them with a third-
party utility called USB Overdrive, discussed next.
Other actions you can potentially assign to mouse buttons include:
• Right-clicking, Control-clicking, or clicking with other virtual
modifier keys

• Triple-clicking

• Drag lock (drag without holding down a button)

• Opening apps, documents, URLs, and AppleScripts

• Sending keystrokes (as if you’d typed keys on a keyboard)

• Navigating forward/back in a web browser

• Controlling your system’s volume, brightness, and other settings

• Simulating previous/next/pause/play commands in Music

76
Program an Input Device with USB
Overdrive
Many fine input devices come only with Windows software (or in some
cases, no software at all), but thanks to a piece of shareware called USB
Overdrive, Mac users can fully configure nearly any USB mouse,
trackball, keyboard, gamepad, joystick, or other HID (human interface
device) product—as well as most Bluetooth pointing devices. The app
functions in much the same way as KensingtonWorks and Logitech
Control Center—pick a device, pick a button, pick an action for that
button; repeat as needed.
If you were so inclined, you could get, say, a Logitech Extreme 3D Pro
joystick and program each of its 12 buttons, each of the 8 directions on
its hat switch, the throttle control, the joystick directions, and the twist
rudder control to do something different on your Mac. Of course, the
obvious use would be to program all the controls to work in a game
such as a flight simulator, but I’m just saying…if you wanted each
button to send a different person a blank email message that resulted
in a sound playing on their computer, you could.

Control Anything with a Stream Deck


A favorite tool of gamers, streamers, and podcasters, Elgato’s Stream
Deck is a desktop box in versions that sport 6, 15, or 32 customizable
buttons (or even eight buttons plus four knobs). You press a button (or
turn a knob) and—I know you’ll be shocked here—a thing happens.
What thing? Why, pretty much anything you like.

I have buttons on my Stream Deck dedicated to things like turning on


and off the studio lights I use when recording videos (and even adjust-
ing the brightness and color temperature), muting/unmuting my
microphone, and going to webpages I frequent. But if you think of the
tasks you can automate with scripts, macros, Shortcuts, and other
tools, you can assume any of those can be assigned to a button—and
many others.

77
In fact, I’m underselling the Stream Deck here because beyond assign-
ing unique actions to each button, every button also features a minia-
ture full-color display. That’s right: you can create a custom image that
accompanies the function you assign! Buttons can also change their
appearance based on a state (such as on or off). Pressing a button can
even switch your entire Stream Deck to a different layout, where all the
buttons change their functions. (You might have one layout just for
Photoshop, another for writing, and a third for podcasting.)

Now, it would be fair to say that there are other ways to do virtually
everything a Stream Deck can do. But the convenience comes from
both the direct connection of a single button to a specific task and the
visual feedback (what each button is for) combined with the tactile
pleasure of pressing a button to make a thing happen. If you have a
zillion keyboard shortcuts, assigning some of them to buttons on your
Stream Deck can reduce the burden of remembering so many.

Elgato includes software to customize the buttons (and knobs) on your


Stream Deck and assign them to tasks, but you can also use plugins to
connect it to other utilities, such as Keyboard Maestro and Shortcuts.

Tip: Jason Snell has a fascinating article titled Shortcuts, AppleScript,


Terminal: Working around automation roadblocks that explains how
to get a Stream Deck to interact with Shortcuts in a way the plugin
doesn’t inherently support. In another article, Jason explains how to
save a Shortcut as an app and launch that app with a Stream Deck.

Learn About Other Special Input Devices


I’ve mentioned multi-button mice and trackballs, programmable
trackpads, extra keyboard keys, gamepads, and joysticks as examples
of user-configurable input devices. In addition, just about any other
USB or Bluetooth input device can be connected to your Mac, and if it
doesn’t happen to come with its own software, you can likely use USB
Overdrive to program its actions.

78
A few examples of the many special-purpose devices that you might
consider are:

• The AlphaGrip Ergonomic Keyboard looks more like a game con-


troller than a keyboard, and indeed it can serve in either capacity
(and as a pointing device).

• The Leap Motion controller is an infrared sensor that detects the


positions of your hands and fingers in the air and lets you perform
nearly any action with a gesture. Guess which gesture I’ve assigned
to Force Quit.

• Pageflip pedals let you turn the page of sheet music (forward or
backward) when viewing it on a screen rather than on paper.

• RollerMouse products use a horizontal bar, positioned in front of


your keyboard, that both rolls around its axis and slides back and
forth to move your pointer. They also feature buttons for left-,
right-, and double-click, plus Copy and Paste.

• Piano-style keyboards connected directly to a USB port or via a


MIDI interface can be used not only for playing music, but also for
triggering other actions depending on the key or keys pressed.

• X-keys input devices from P.I. Engineering include crazy keyboard-


and keypad-like button arrays, with or without an analog joystick or
jog & shuttle control, foot pedals, and other switches.

79
Automate Text Expansion
Even if you’re a great typist, you can save time and increase your
accuracy by using software that watches what you type and dynamical-
ly replaces abbreviations you’ve previously specified with longer
chunks of text. (And if you’re not a great typist, such software can
increase your effective typing speed!)

I mentioned earlier that whenever I type dttg, my Mac automatically


expands that into DEVONthink To Go. That’s just one of dozens of
abbreviations I use in my own work. I also use TCo to produce Take
Control of, syp to produce System Preferences, and so on. The longer
and more complex the text in question, the more useful automatic text
expansion becomes.

Text expansion isn’t just for names and short phrases. You can use it
for addresses, phone numbers, URLs, boilerplate text for common
email replies, HTML code snippets, and so on. Depending on which
software you use for text expansion, your snippets might also include
styles (such as bold and italic), graphics, the current date or time,
variables, AppleScripts or shell scripts, the contents of the clipboard,
and more.

The great thing about text expansion is that you don’t have to do
anything special to use it—you simply type. You don’t need modifier
keys like Command or Control, and you don’t need to hunt for menu
commands. And it can be used nearly anywhere.

One catch, however, is that you must be careful when choosing abbre-
viations—since text expands as you type, you might end up making a
lame mistake if you’re not paying attention. For example, I thought I’d
use km as an abbreviation for Keyboard Maestro, but then I tried typing
a distance in kilometers and got a surprising result! So be sure to use
abbreviations that will never occur on their own, or even as part of
another word. One technique many people use to solve this problem is
to double the first or last letter, as in kmm for Keyboard Maestro. Anoth-
er is to add a slash (/) to the beginning of each abbreviation.
80
Note: Although I say “text expansion,” the very same feature can be
used for simple replacements, even if the replacement isn’t longer.
For example, if you frequently mistype “the” as “teh,” you could use
text expansion to replace the latter with the former—or you can
correct “MacWorld” to “Macworld” and “PhotoShop” to “Photoshop.”

Use Text Replacement in macOS


macOS includes its own rather rudimentary text-expansion capability,
known as text replacement.

To configure text replacement:

1. Go to System Settings > Keyboard > Text Replacements (Ventura or


later; Figure 28) or System Preferences > Keyboard > Text (Mon-
terey or earlier).

Figure 28: Set up macOS text replacements here. This image shows
the window after numerous replacements have been added.

81
2. Click the plus button.

3. Type the text you’ll type in the left-hand (Replace) field, and then
type the text you want to end up with in the right-hand (With) field.

Tip: Although replacement text can’t include a Return character, you


can type Option-Return to include a line break.

4. Press Return.

Repeat these steps as needed to add further abbreviations.

Tip: To add abbreviations for special characters (such as fractions, as


shown in Figure 28, above), choose Edit > Emoji & Symbols and
type your term into the search field (fraction, say).

Once configured, text replacement is seamless: you type one of your


abbreviations, and as soon as you press a trigger key—Space, Tab, or
Return, or a punctuation character—the abbreviation is replaced with
the text you’ve specified. Abbreviations are not case-sensitive, so if you
set up myurl to expand into http://www.myurl.com/, then that will
happen even if you type MyURL.

Your abbreviations even sync across your Macs and iOS/iPadOS


devices if they’re all signed in to the same iCloud account and iCloud
Drive is selected in System Settings > Account Name > iCloud or
System Preferences > Apple ID > iCloud.

Although text replacement works well enough for what it is, this
feature has numerous limitations:

• It doesn’t work in all apps; the only way to know where it does work
is to look for the Edit > Substitutions > Text Replacement menu
command, make sure Text Replacement is selected, and then try
your abbreviations. (For example, it doesn’t work in BBEdit or
Word—but Word has its own built-in text-expansion feature.)

• If your replacement text is longer than about 25 characters or uses


the Option-Return trick for multiple lines, the text will be cut off in
the Keyboard setting/preference pane—you won’t be able to read it.

82
• You can’t configure the trigger characters that cause abbreviations
to expand.

• You can’t include styled text, graphics, variables, or other such


niceties.

So, if you like the idea of text expansion but find the Mac’s built-in
feature too limited, it’s time for a more powerful, third-party tool.

Use a Third-Party Text Expansion Utility


For vastly more power and flexibility when it comes to text expansion,
turn to a third-party utility. At the moment, I’m aware of four main
contenders for macOS that are under active development: aText,
TextExpander, Typinator, and TypeIt4Me. (For the purpose of this
topic, I’m restricting myself to standalone tools for text expansion.
There are also multipurpose tools that can perform this task. Alfred, a
launcher app, also includes an automated text expansion feature in its
optional Powerpack add-on. The Raycast launcher also offers text
expansion via its Snippets feature. BetterTouchTool can use a key
sequence to trigger an action, including typing replacement text; see
Use BetterTouchTool. And Keyboard Maestro can use arbitrary typed
shortcuts to launch any macro, including one for typing or pasting text;
see Control Your Mac with Keyboard Maestro.)

These four tools share many features in common beyond mere text
replacement—for example, all of them can:

• Insert the current date or time (or a portion of it, such as “Tuesday”)

• Respect case when expanding abbreviations

• Insert snippets that include styled text and graphics

• Ignore certain apps where you don’t want text expansion to occur

• Include the contents of the clipboard in the expanded text

• Perform simple calculations on numbers and dates, including


variables

83
• Reposition the insertion point to any arbitrary location after
expanding text

• Use abbreviations to trigger AppleScripts

• Sync clippings and abbreviations via Dropbox

These four utilities are much more alike than different, and most users
should be equally content with any of them. I will, however, point out a
few distinguishing characteristics:

• aText: aText strikes me as having the least-polished interface of the


four utilities—it doesn’t even include online help or any other
documentation—but what it lacks in looks it makes up for in an
extensive feature set. Among other things, snippets can include
editable fields, and can launch shell scripts as well as AppleScripts.
aText is also the least expensive option, at $4.99.

• TextExpander: Like aText, TextExpander has editable fields for


fill-in-the-blanks snippets. It also includes some spiffy predefined
shortcuts, such as one that uses AppleScript to shorten any URL on
your clipboard with a service such as bitly.com or is.gd.

Tip: The Smile blog has a fantastic post about how to perform Cur-
rency Conversion with TextExpander, with a little bit of AppleScript
and a small helper app.

• Typinator: Typinator, from the developer of KeyCue (discussed


earlier) is right up there on the feature comparison checklist, with
fill-in-the-blanks snippets, date and time calculations, and scripting
support, among dozens of other capabilities. You can download a
free AppleScript snippet called Conversions that performs currency
conversions (among other things). Typinator also supports regular
expressions, which means that expansions can be triggered with
user-defined patterns, not just fixed abbreviations—and the replace-
ments can also be pattern-based. However, unlike the other apps in
this list, Typinator doesn’t let you define which delimiters trigger
expansion—abbreviations can expand either as soon as you finish
typing them or at word boundaries, but you can’t specify which

84
characters can signal the end of a word. And unlike TextExpander
and TypeIt4Me, it currently has no iOS counterpart. At the end of
this book, there is a 30%-off coupon for Typinator.

• TypeIt4Me: TypeIt4Me has been around the longest—since way


back in 1989! As a result, it feels a bit dated in spots. For example,
its fill-in-the-blanks feature, called AutoCue, pauses expansion of a
snippet, with text selected, while you enter the content you want,
and then continues when you press Tab. That’s clunkier than a
simple dialog with fields for entering all the values at once, but it
gets the job done. On the other hand, it can use Apple’s spelling
dictionaries (in multiple languages) for autocorrect. It also has an
iOS counterpart (TypeIt4Me Touch), although it’s not quite as
capable as TextExpander for iPhone & iPad. You can save 30% on
TypeIt4Me with the coupon at the end of this book.

The more time you spend working with a text-expansion tool, the more
ideas you’ll come up with for putting it to good use. Here are a few I
haven’t mentioned already:

• Enter special characters without remembering how to type them.


For example, eurosymbol could “expand” to €, while rightarrow
could produce → and thumbsup could give you the emoji.

• Enter several paragraphs of greeked text (which is usually, in fact,


based on Latin) such as “Lorem ipsum…” with a quick abbreviation,
such as lipsum.

• Type your Mastodon handle, with or without an embedded, click-


able link, with an abbreviation such as @mst.

• Replace your email app’s signatures with custom signature snippets


that appear wherever and whenever you need them.

Just to show you how this works, let me walk you through the steps of
creating and using an abbreviation in TextExpander:

1. From TextExpander menu in the menu bar, choose New Snippet.

2. In the main content area, type the text you want to end up with,
such as supercalifragilisticexpialidocious.

85
3. In the abbreviation field, type the abbreviation you want to use,
such as scfl. (Be sure not to reuse an abbreviation you used in
System Preferences > Keyboard > Text.)

4. Close the TextExpander window.

5. Now open an app where you can type text (like TextEdit or Mail).

6. Type your abbreviation scfl and then a space or other punctuation.


With a “pop” sound, your abbreviation disappears and is replaced
with “supercalifragilisticexpialidocious.”

Clean Up Your Text with TextSoap


Text expansion is handy, no doubt about it, but sometimes your text
needs help of another kind. For example, do you often find extra
spaces or return characters, duplicate lines, or text in the wrong
case? Do you find URLs or dates in the wrong format, styled text that
should be in HTML or Markdown instead (or vice versa), or other
annoying errors? An app called TextSoap can solve these and thou-
sands of other problems, often with one click.
Where a built-in solution isn’t quite what you need, you can make
your own with a combination of regular expressions (a powerful
pattern-matching system) and styles, and you can even build elabo-
rate multi-step macros to manipulate text any which way. Thus, it’s
somewhat like a subset of Nisus Writer Pro (see Automate Nisus
Writer Pro)—the Find/Replace capability and a portion of the macro
language, but without all the other word-processing features. Anyone
who works extensively with text can find many uses for such a tool.

86
Automate the Finder
The Finder is a special app that runs all the time and lets you navigate
all the files, folders, and apps on your Mac. You use the Finder to
organize, tag, and locate files; connect to other devices on your net-
work; mount and unmount servers and external drives; and perform
numerous other activities that involve files, folders, and volumes.
The Finder is also the main place people go to open apps that don’t
appear in the Dock. When you want to launch an app, you might open
a Finder window, click Applications in the sidebar, scroll to the app
you want, and double-click it. Similarly, if you want to open a docu-
ment in its default app, you might dig through any number of nested
folders in the Finder and then double-click that document.
Since you use the Finder so much, it offers prime opportunities for
automation. For example, it’s possible to launch apps and open docu-
ments without clicking and scrolling through any windows. In a second
or less, while keeping both hands on the keyboard, you can open an
app or document without even knowing where it’s located.
In this chapter, I discuss how to get started automating the Finder
using Spotlight, and then I move on to more powerful third-party
utilities that let you do even more.

Tip: As you’re working in the Finder, don’t forget about the Mac’s
Quick Look feature. Just press Space with a file selected to see a full-
size preview instantly without having to open an app—many common
formats are supported. Quick Look also works in most launcher apps.

Use Spotlight as a Launcher


Spotlight, the Mac’s built-in file indexing and search feature, has
always been an excellent way to launch apps (and open files) too. You
can activate Spotlight with a click on the Spotlight menu or a

87
keyboard shortcut, type a few letters of the app you’re searching for,
and press Return to launch it as soon as it’s highlighted.

In recent versions of macOS, Spotlight has become a better launcher,


as well as an all-purpose tool for searching the web, performing calcu-
lations, and controlling other aspects of your Mac’s operation. In fact,
Apple not-too-subtly changed Spotlight’s appearance and behavior to
more closely resemble third-party launchers such as Alfred and
LaunchBar, discussed just ahead (see Use a Third-Party Launcher).

Spotlight isn’t perfect, by any means, but once you get the hang of it,
it’s a pretty good way to find stuff.

To use Spotlight as a launcher:

1. Press ⌘-Space or click the magnifying glass icon in your menu


bar to display the Spotlight window.

2. Begin typing an app’s name (Figure 29). If the app’s name is made
up of multiple words, you can type the first letter of each (such as ka
for Keychain Access); you can also type InterCapped letters, as in bc
for BusyCal. Wait while Spotlight searches. As it finds matching
items, it lists apps at the top.

Figure 29: The Spotlight window as it appears for me after typing m.

88
3. If the app you want to launch is highlighted as the top hit, press
Return to launch it. If it’s not the top hit, you can either continue
typing to narrow down the search or press the ↓ key until the app
you want is highlighted. Then press Return.

The app opens. This works regardless of where the app is located on
your Mac.

You can use the same technique to open documents, Music tracks,
Contacts records, Safari history items, and so on. You can also use it to
look up words in the dictionary and to perform web searches.

Many of these search results—including Wikipedia entries, maps,


dictionary definitions, and contact records—appear in the built-in
Spotlight preview pane to the right, so there’s no need to open a
separate app (and, in fact, you can skip pressing Return). Spotlight can
also do mathematical calculations and currency conversions. For
example, type (17*3)/12 or $120 in euros, and the result will appear in
both the search window and the preview pane.

Furthermore, Spotlight is adaptive—whichever app you selected last


after typing a given letter or letters will appear first on the list the next
time you type the same thing. However, all non-app matches will be
farther down on the list, likely requiring multiple arrow presses to get
to them. (You can customize the order of the categories in System
Settings > Siri & Spotlight > Search results in Ventura or later, or
System Preferences > Spotlight > Search Results in Monterey or
earlier.) Also, be aware that the list won’t show every possible match,
so you may have to click Show All in Finder (at the bottom of the list)
to open a new window with complete search results.

Even if you restrict yourself to opening apps from the keyboard with
this method, Spotlight tends to be kind of slow. And because its results
change over a period of several seconds, it often takes that long to be
sure that the thing you want will still be highlighted when you press
Return. So you can’t blindly type in a few characters and trust that the
right thing will open.

89
But with a bit of extra software, all these problems can magically
disappear—and you can gain significant new capabilities.

Use a Third-Party Launcher


If your goal is simply to use your keyboard to launch apps, open an
occasional document, and perhaps do a few calculations, Spotlight
might be adequate. But wouldn’t it be even better if you could use that
same ⌘-Space shortcut (or another one of your choosing) as a sys-
temwide trigger to perform dozens of other common actions, too? If so,
you’re the type of person who can use a third-party launcher.

Here are the sorts of things a third-party launcher can do that the
Spotlight menu can’t:

• Learn your preferences as you use it, so that your most frequently
used items automatically bubble to the top of the list (and therefore
require fewer keystrokes)—even if those items aren’t apps

• Display matching items instantly

• Browse your Music library for music by song, artist, composer,


album, genre, or playlist—and control music playback

• Perform actions other than opening items—for example, sending


the items via Mail or Messages, compressing files in the Finder,
moving them to another location, or adding tags

• Add calendar events using only the keyboard

Mac users have five excellent choices in launchers: Alfred, Butler,


LaunchBar, and QuickSilver, plus a newcomer called Raycast. Each of
these utilities approaches the task a bit differently from the rest,
offering its own unique features and user interface. And each of them
has a ton of vocal supporters who insist that their favorite launcher is
far superior to all the others. I have my own preference, but I acknowl-
edge that all of them have merits, and I won’t think (much) less of you
if you choose a different one.

90
Note: Keyboard Maestro (see Control Your Mac with Keyboard Mae-
stro) also has an app launcher that you can activate with a user-
defined keystroke, but I don’t include it in this list because it’s less
powerful and less convenient to use than standalone launchers—and
it doesn’t learn your preferences as you use it.

The typical way you use a launcher is much like the way you use the
Spotlight menu from the keyboard. Press Control-Space (or whichever
hot key you’ve selected) to open a window or other widget, and then
begin typing.

In most cases, after a bit of training, the launcher matches whatever it


was you were looking for with only one or two characters. Then, press
Return to open that thing. For example, to open Mail, I press ⌘-Space,
m, and Return. Of course, that’s just the sequence for the basic task of
opening an app or file; you might type different characters, or use a
different hot key or string of commands, to perform additional actions.

Note: Although Spotlight uses ⌘-Space by default, if you’d prefer to


use that shortcut for a third-party launcher, you can change what
Spotlight uses (for example, to Control-Space) by going to System
Settings/System Preferences > Keyboard > Keyboard Shortcuts
(Ventura or later)/Shortcuts (Monterey or earlier) > Spotlight.

Here’s a brief rundown of the five major Mac launcher utilities.

LaunchBar
I’ve used LaunchBar since 2002, and even though I’ve tried all the
other launchers (more than once), I always come back to LaunchBar
because it just feels right to me. It works the way I think (or vice versa).
And, you can save 20% on LaunchBar with the coupon at the end of
this book.

You activate LaunchBar with a hot key—it’s ⌘-Space by default (which


I prefer, so I changed Spotlight to be Control-Space). Start typing (the
name of an app, file, contact, or whatever) and, when the right item is
selected (Figure 30), press Return to open it.

91
Figure 30: After activating LaunchBar with ⌘-Space (or a custom
keystroke), type a letter or two (M in this case) to see matching apps
and other items.

You don’t have to type the first letters of the name exactly; for example,
I type nw for Nisus Writer Pro and oo for OmniOutliner. If you type an
abbreviation and then select something other than LaunchBar’s top
pick, it remembers that, and as you use it, it molds its suggestions to
your actual usage.

LaunchBar has many other talents, too. If you press the hot key and
then start typing numbers, LaunchBar assumes you want to perform a
calculation, and lets you do so without any other preliminaries (just as
Spotlight does). You can also use a feature called Instant Send to do
interesting things with selected files or folders—for example, email
them, open them with a non-default app, or run an AppleScript on
them. I use LaunchBar for looking up contact phone numbers, tracks
in Music, and many other things. LaunchBar can also remember items
previously copied or cut to your Clipboard and recall them later.

Tip: To learn about LaunchBar’s six superpowers and much more,


read Kirk McElhearn’s book Take Control of LaunchBar.

92
Alfred
When you press Alfred’s hot key, a large floating window appears.
(Alfred uses Option-Space by default, an unfortunate choice since that
types a nonbreaking space in many apps.) Start typing the name of an
app, file, or other content, and Alfred displays matches immediately.
You can also type keywords to perform commands such as restarting
your Mac or hiding the current app. Alfred has hundreds of features
and nearly every aspect of the app is highly customizable.

Although Alfred itself is free, some of its most interesting features


require a purchase of the optional Powerpack, which—among other
things—adds automatic text expansion, access to Contacts, email
searching, 1Password integration, a clipboard history, and workflows
(which combine Alfred features with system commands and scripts to
form macro-like tools; see Use Another Macro Utility).

Butler
Butler pops up a floating window when you press its hot key (Control-
Space by default), and as you start typing, the results initially look
much like those in the Spotlight menu. However, unlike Spotlight,
Butler can learn your favorite apps, files, and other items as you use it.
You can also trigger Butler with a menu, hot corner, or user-defined
abbreviation. Butler offers the usual range of launcher actions: opening
files and apps, searching the web, running AppleScripts, controlling
music playback, and so on. It also includes a clipboard history (see Use
a Macro or Launcher Utility).

Unfortunately, although Butler has lots of capabilities, I find its user


interface nearly inscrutable, and its included documentation isn’t
much help. Perhaps it was just designed for someone who approaches
software differently than I do, but it seemed to require too much
thought and effort to decode its features, problems I didn’t experience
with any other launcher I tried. Furthermore, a major update from
Butler 4 (the current version) to Butler 5 has been promised since at
least 2012, which may tell you something about its pace of develop-
ment.

93
Quicksilver
Quicksilver is a free (donations accepted), slick, and highly modular
launcher. It includes just a few built-in features, but you can add any of
dozens of free plugins to enhance the app with additional capabilities.
Some of these plugins provide controls for specific apps (Apple Mail,
Evernote, Google Chrome, Music, Safari, and others) while others add
lower-level features (such as image and text manipulation, access to
the windows and menus of open apps, calculations, a clipboard history,
and text manipulation).

You bring up the Quicksilver display by pressing a hot key (Control-


Space by default), and then start typing to find items to launch. You
can also assign hot keys to many other actions, such as music controls.
With the right plugins, you can also trigger actions with mouse actions,
trackpad gestures, or system events (such as an application quitting or
a file being compressed).

Raycast
Raycast is the hot new thing. Superficially, it’s much like the others in
this list: you can quickly launch apps, control your music, perform
calculations, add calendar entries, and so on with just a few keystrokes.
It also includes a clipboard history, and offers a snippet feature for
expanding abbreviations (like TextExpander and similar utilities; see
Automate Text Expansion). Of course, it learns as you use it, too. As
with Alfred, the default keyboard shortcut to activate it is the unfortu-
nately chosen Option-Space, but you can change it.

The most compelling aspect of Raycast, however, is that it has an


integrated tool for developing extensions to add new features. Devel-
opers can share these extensions in the Raycast Store—a slightly odd
name, since everything in the store is free (at least for now)—and users
can install them in seconds. Among the nearly 1,000 extensions
available at publication time are ones that integrate support for apps
such as 1Password, BetterTouchTool, and DEVONthink; format
conversions of many kinds; all sorts of text manipulations; and tie-ins
to a vast number of websites and online services.

94
Not only is Raycast impressive, it’s also undergoing rapid develop-
ment, something I can sadly no longer say for LaunchBar. So it has a
good shot at becoming my new favorite soon. Raycast is currently free,
and will likely always be so for individual users. Features for business
teams, and future capabilities such as Artificial Intelligence (AI)
features, may at some point require a fee.

Organize Files with Hazel


You’re probably familiar with the way email rules work (whether or not
you use them yourself; see Automate Email). When a message comes
in, your email app checks to see if the conditions in your first rule
match. If so, it performs the actions associated with that rule (such as
filing the message in a mailbox, deleting it, or replying to it); if not, it
moves on to the next rule.

A clever utility called Hazel does the same thing, except for files in the
Finder rather than for email messages. You can save 20% on Hazel
with the coupon at the end of this book. (And, you should find Hazel’s
built-in help especially helpful—I wrote it!)

In the Hazel app, you select a folder and then set up one or more rules
for it (Figure 31).

Figure 31: Rules in Hazel look and act much like rules in Mail—
except they target files rather than email messages.

Rules can look for conditions such as how recently a file was created or
modified, its name, its size, tags, and other attributes. When it finds a
match, Hazel can perform one or more actions such as applying a tag,

95
moving or copying the file into another folder, deleting the file, com-
pressing or decompressing it, importing it into Music or Photos (for
music and photos, respectively), displaying a notification, or running
an AppleScript or shell script.

Hazel rules have an effect similar to AppleScript Folder actions (flip


ahead to Use AppleScript Folder Actions) and launchd actions that
watch a folder (see Use Launchd and Watch a File or Folder). But
Hazel rules require no coding, so they’re far simpler to use.

Hazel can also keep your Trash from overflowing with old and/or large
files, help you completely remove all traces of apps you delete, and
remove duplicate files.

I’ll admit that the first time I heard about Hazel, I was afraid that it
would move things around without my knowledge, with the result
being that I’d lose (or at least lose track of) things rather than have a
tidier Mac. I mean, I put files in particular places for a reason, and I
didn’t want some smart-alecky app making up its own mind about
where things should go. But in fact, Hazel does only what you expressly
ask it to do. And if it makes you more comfortable, it can alert you
when it moves or deletes something so that there are never any sur-
prises.

Here are some examples of what Hazel can do for you:

• Keep your Downloads folder clean. If you haven’t manually re-


moved a downloaded file after a week or so, Hazel can archive or
delete it based on rules you’ve set up.

• Add music files that appear in your Dropbox folder to Music. It can
delete the (now redundant) originals, too.

• Keep your Desktop clutter-free by moving files into project-specific


folders if they’ve been on your Desktop for a few weeks without
being opened.

• Alert you when a shared folder changes (say, for a project you’re
working on with someone else).

• Add photos from Dropbox to your favorite photo-management app.

96
It’s easy to get carried away with a tool like this, but I prefer to think of
it as a way to automate a few specific file-management tasks that
would otherwise require my time and attention.

Enhance Open and Save Dialogs with Default Folder X


I was shocked to realize that this book, which reached its fourth
edition after eight years, never mentioned an excellent utility I rely
on every day: Default Folder X. Perhaps that’s because it doesn’t fall
into one of the existing automation categories I cover, or because it
is so fully integrated into my Mac usage that I never think about it.
(As this book’s editor, Glenn Fleishman, says, “It’s like the air we
breathe!”)
Default Folder X isn’t an automation tool as such, but it does offer
essential shortcuts that make my life easier and my work more fluid.
As the name suggests, it lets you set a default folder for each of your
apps, which then appears automatically in Open and Save dialogs.
But that’s just the beginning. It also enhances those dialogs in
numerous other ways: listing recent files, folders, and open Finder
windows; letting you set app-specific favorite files and folders;
offering fast navigation anywhere on your Mac; and much more. If
you don’t already use it, I strongly suggest giving it a try!

97
Supercharge Your
Clipboard
Cut, copy, paste. You’ve probably done those things thousands of times
without even thinking about your clipboard, the temporary storage
space macOS uses to hold whatever you’ve cut or copied. The Mac’s
built-in clipboard is boring, but numerous utilities can supplement or
replace it with powerful new capabilities that will save you time and
effort.

Note: iCloud’s Universal Clipboard automatically syncs your clipboard


across your devices, as long as they’re signed in to the same iCloud
account, have Wi-Fi and Bluetooth enabled, and are near each other.
That’s neat, though I’ve found it less than perfectly reliable. See How
to use Universal Clipboard on Your Mac at iMore for details.

With one of these utilities installed, you’ll never again have to worry
about your Mac crashing right after you’ve cut or copied something but
before you paste it. You’ll also be able to see and use things you copied
to your clipboard hours or days ago, change the clipboard contents
between the time you copy it and the time you paste it, and more.

Learn What a Clipboard Utility Can Do


You might think you can do just fine without a clipboard utility, but
remember: people used to think that about cars and microwave ovens,
too! Here are some of the groovy tricks you’ll be able to perform:

• Access your clipboard history: By default, every time you cut or


copy something to the clipboard, whatever was there before disap-
pears. By contrast, every utility mentioned in this chapter maintains
a clipboard history, which is to say you can view a list of dozens or
hundreds of previous clipboard items and paste any of them at will.
(I especially like using a keyboard shortcut, such as ⌘-Control-V, to

98
paste the just-previous item from my clipboard history—that way, I
can easily copy two different things and then paste them both
consecutively.)

• Juggle multiple clipboards: What if you had not just a single


clipboard (with a historical record of its contents) but two, five, or a
dozen clipboards—each with its own name? If you need to copy
things independently of each other and refer to them by name or
category, multiple clipboards may be just the thing.

• Store and reuse clippings: Normally, your Mac’s clipboard is


cleared when you shut down or restart. Most clipboard utilities
preserve not only your current clipboard but also your clipboard
history across restarts. Some even let you manually save and name
clippings for future reuse.

• Edit a clipboard’s contents: Say you’ve copied something you


intend to paste multiple times—but you find an error in the copied
text. Some clipboard utilities let you edit what’s on the clipboard
before you paste it, so that every pasted copy will be correct.

• Filter a clipboard’s contents: Perhaps you’ve copied styled text


but want to paste it as plain text. Or maybe you want to do some-
thing far more elaborate—perform find/replace operations or
mathematical calculations on the copied text, add to it or trim it,
change its case, or manipulate it in some other way. All this is
possible with a utility that can filter a clipboard’s contents.

Still can’t quite imagine how you’d use a clipboard utility? Let me give
you some concrete examples of how I do:

• Copy the title of an article on the web, copy its URL, and then paste
the two in sequence without having to switch back to a browser

• Cut paragraphs or bullet points from several different locations in a


book, and then paste them all together at a new spot

• Copy the URL for a product at Amazon and paste it with my affiliate
link baked right in

99
• Copy raw HTML code but paste it with Markdown formatting, or
vice versa

• Copy a large chunk of text and paste it with any duplicate lines re-
moved

The last three items in this list are examples of filtering, which saves a
tremendous amount of tedious work.

Use a Macro or Launcher Utility


You may already have a utility on your Mac that includes many or all of
the clipboard enhancements you’d like—macro utilities such as Key-
board Maestro and launcher utilities such as LaunchBar often have
such capabilities.

I’m all in favor of multipurpose tools, and if one of these meets your
needs, that may be the best solution for you. On the other hand, if you
need extra features (or don’t have a suitable macro or launcher utility),
I’ll tell you about several standalone clipboard tools ahead in Use a
macOS Clipboard Utility.

Keyboard Maestro
I talk about Keyboard Maestro’s macro capabilities later, in Control
Your Mac with Keyboard Maestro; there’s also a coupon at the end of
the book for a 20% discount. For now, I want to mention its clipboard
capabilities:

• Multiple, named clipboards

• A history for your primary clipboard (Figure 32)

• Filtering the contents of any clipboard while pasting it, according to


rules you set up

• Optionally pasting plain text, even if you copied styled text

• Access to persistent clippings that you can see and use even after
restarting your Mac

100
• User-definable hot keys for working with clipboards

Figure 32: Keyboard Maestro’s clipboard switcher and history


window.

Note: Keyboard Maestro, like many of the utilities in this book, uses
the term hot key (or hotkey) as a synonym for keyboard shortcuts.

All this is extremely snazzy, and it’s nearly everything I could want
from a clipboard utility. Keyboard Maestro doesn’t, however, let me
manually edit a clipboard, nor does it offer a way to sync my clipboard
history across Macs (although it can send a clipboard from one Mac to
another).

Launcher Utilities
In the previous chapter, I told you how to Use a Third-Party Launcher
to do things like opening apps, playing tunes, and performing calcula-
tions. All the launchers I mentioned—LaunchBar, Alfred (with the
optional Powerpack), Butler, Raycast, and QuickSilver—also keep
clipboard histories, so you can copy multiple things and then paste
earlier clippings. But, they also offer some other clipboard features
worth mentioning.

101
LaunchBar, Alfred, and Raycast can paste a clipping as plain text,
preserve clippings when you restart your Mac, and merge whatever
you’re copying with what’s already on the clipboard. In addition, Alfred
lets you name your clippings. Butler refers to clipboards by their
technical name, “pasteboards,” and offers persistent clippings, named
clippings, and user-definable hot keys for working with clipboard
contents.

Unfortunately, none of the launcher apps can filter clipboard contents,


which I think is one of the most useful clipboard capabilities.

Use a macOS Clipboard Utility


If you don’t use a launcher like LaunchBar—or if you do, but crave
even more clipboard power—you have a bunch of options. I now use
either Keyboard Maestro or LaunchBar (both of which are running on
my Mac all the time anyway) to provide a clipboard history and other
clipboard tools. (Which one I use at any moment depends on my exact
needs.) However, if you prefer a standalone clipboard utility, there are
many—in fact, dozens—from which you can choose. Some examples, in
alphabetical order:

• Copy’Em

• CopyClip 2

• CopyLess 2

• CopyPaste Pro

• Paste

• Pastebot

Note: Just a quick comment about Paste, newly added to this list: it
can sync your clipboard history across your Macs, iPhones, and iPads,
a rare and wonderful capability!

102
Automate Individual Apps
Later in this book, I talk about systemwide automation technologies
built into macOS like Shortcuts, AppleScript, and Automator, which
can automate the actions of individual apps. But there’s often a bet-
ter—or, at least, more thorough—way of doing that within an app itself.
That’s the topic of this chapter: using apps’ built-in automation capa-
bilities.

Due to the breadth and depth of in-app automation features, I can only
provide an overview, basic instructions, and a few examples. You’ll be
able to accomplish some basic tasks and discover how to learn more.

I begin with Microsoft Office, partly because of its popularity and


partly because of its extensive built-in programming language. I then
move to Nisus Writer Pro, the very app I’m using to type these words,
to illustrate a few different forms of automation that should be useful
to anyone who works with words. Then I briefly discuss Google Apps
Script, a macro language for Google Apps, and list the automation
capabilities of several other popular apps.

Tip: If you want to automate Apple’s iWork apps (Pages, Numbers,


Keynote), you’ll need to use either AppleScript or Automator. You can
learn more about AppleScript for iWork at iWork & Automation:
Productivity Enhanced, part of the Mac OS X Automation site.

Automate Microsoft Office


Microsoft Office—which in macOS comprises Word, Excel, Power-
Point, Outlook, and OneNote as its main components—is one of the
world’s best-known software packages. Microsoft long ago added a
programming language to the suite called Visual Basic for Applications
(VBA), which enables users to write macros that automate Office apps,
optionally embed those macros in documents, and run them (with
some limitations) on either macOS or Windows. Microsoft removed

103
VBA from Office 2008 for Mac, but brought it back in Office 2011. It’s
still there in Office 2021 (also available as part of an Office 365 sub-
scription), and presumably, it will be in future versions too. (Microsoft
Office also has excellent AppleScript support, which is an alternative
way to accomplish many of the same tasks.)

Note: In Office for Mac, only Word, Excel, and PowerPoint support
VBA.

What can you do with an Office macro? The sky’s the limit, but here
are a few simple examples, any of which could be done with a single
click or keystroke:

• Perform a frequently used find-and-replace operation

• Format spreadsheet cells according to their contents

• Number all the instances of a certain phrase in a document

• Reformat a table

• Remove all the hyperlinks in a workbook

• Change all the tab stops in the current paragraph style

• Merge cells from two columns into a third column

• Resize all the graphics in a document

If you use Office extensively—and especially if you share documents


with Windows users—it might be worth the effort to learn a bit of VBA
since (unlike AppleScript) its macros work on both Windows PCs and
Macs. But let me be frank: it’s not great for beginners. VBA was de-
signed for programmers, not for ordinary users. It won’t do you any
good beyond Office apps, and unlike AppleScript, VBA would never be
called “English-like.” If you don’t know much about programming
already, there’s a significant learning curve.

However, there’s a sneaky way to get your foot in the door—to write a
VBA macro without knowing any VBA at all. Office lets you record
macros—that is, turn on recording, do some stuff while Office watches,

104
and then turn off recording. Office then attempts to make a VBA macro
out of whatever you just did, which you can then replay at will. Some-
times these macros work fine as is; sometimes they require fiddling;
and sometimes you’re out of luck.

So, my advice if you want to automate an Office app is to try recording


a macro first. If that doesn’t work (and you can’t easily see how to fix
it), move on to Automator. If Automator won’t do what you need
either, try either AppleScript (if you need more control) or Keyboard
Maestro (if you want a simpler interface). Write your own VBA macro
from scratch only if no other tool does the trick.

Record Macros in Microsoft Office Apps


Let’s walk through the process of recording and then playing back a
simple macro. (I’ll use Word for this example, but the process is
virtually identical in Excel and PowerPoint.)

1. Open a new, blank document in Word. (It doesn’t have to be blank,


but it’s easier that way for this example.)

2. Choose Tools > Macro > Record Macro.

3. In the dialog that appears (Figure 33), give your new macro a
name (like Test) and click OK.

Figure 33: In this window, you define a new macro before you begin
recording it.

105
Tip: If you want to assign a keyboard shortcut to your macro now,
you can. Before you click OK in this dialog, click Keyboard, press the
desired keyboard shortcut, and click OK. But you can also Assign a
Keyboard Shortcut to a VBA Macro later.

4. Now perform some actions—click buttons, choose menu commands,


run a Find/Replace, or whatever you like. For the purpose of this
exercise, I suggest doing the following:

a. Type the word First, press Tab, type Second, and press Return.

b. Type Third, press Tab, type Fourth, and press Return.

c. Press ⌘-Shift-↑ to select the second paragraph.

d. Press ⌘-B to turn the selected text bold.

e. Press Shift-↑ to add the previous paragraph to the selection.

f. Select Table > Convert > Convert Text to Table and click OK.

g. Press ↓ to move the insertion point below the table.

5. Choose Tools > Macro > Stop Recording.

That’s it; you’ve recorded a macro. In theory, you can replay the exact
actions you took again, at any time, in any document. So let’s try.

To play back your macro:

1. Choose Tools > Macro > Macros.

2. Select the macro you just recorded (it will likely be selected by
default).

3. Click Run.

If everything is working correctly, your document will get two more


table rows that look exactly like the two that were already there.

Curious to know what your macro looks like in VBA? Choose Tools >
Macro > Macros, select your macro, and click Edit. You see something
like Figure 34.

106
Figure 34: Here’s what the macro we just recorded looks like in
Visual Basic.

Beautiful, isn’t it? No, of course not, but if you look carefully, you can
probably make out approximately what the commands do. If you were
so inclined, you could edit the macro right here—for example, substi-
tute different words in the Selection.TypeText Text: lines.

To get out of the editor, choose File > Close.

Assign a Keyboard Shortcut to a VBA


Macro
Going through Tools > Macro > Macros and a separate window when-
ever you want to run a macro is a drag. Fortunately, you don’t have to:
you can assign a keyboard shortcut to your macro. In Word or Excel
(but not PowerPoint), follow these steps:
1. Choose Tools > Customize Keyboard.

2. In the Categories list on the left, select Macros.

3. In the Commands list on the right, select the macro you want to
assign a keystroke to.

4. Click in the Press New Keyboard Shortcut field.

5. Press the key combination you want to use. (See the sidebar Use
Multi-Key Shortcuts in Microsoft Word, below, for a special tip.)

107
6. Click Assign.

7. Click OK to dismiss the window.

From now on, you can activate your macro with that keyboard short-
cut.

Use Multi-Key Shortcuts in Microsoft Word


A little-known and useful fact about Word (which does not apply to
Excel or PowerPoint, by the way) is that keyboard shortcuts can
include sequences—to a point.
For example, you could assign Control-P,B to insert a page break
(Insert > Break > Page Break). The way this would work is that you’d
press Control-P, and as long as the next key you pressed within 5
seconds was a B, you’d get a page break. If you pressed any other
key, or no key at all, during those 5 seconds, nothing would happen.
I used Control in my example, not Command, because all single
alphabetic ⌘-key shortcuts are preassigned, and even though you
can create your own shortcuts that override them, sequences are
ignored in such cases. For example, if I assigned ⌘-P,B to Page
Break, it would have to override ⌘-P for Print—but then, as soon as I
pressed ⌘-P (and without waiting for the B), the page break would
be inserted. I know, weird.
So that’s one limitation. Another is that sequences can have at most
two characters (plus modifiers)—you can’t assign Control-P,B,J to a
Peanut Butter & Jelly macro. Still, two-key sequences starting with
Control are useful mnemonic aids.
To set one up, follow the directions above, but type the sequence
(such as Control-P, followed by B) in step 5. Word shows sequences
with a comma (Control-P,B), but you won’t actually type the comma.
Nisus Writer Pro offers vastly more flexibility in assigning multi-key
shortcuts. See Use Multi-Key Shortcuts in Nisus Writer Pro.

Run an Existing VBA Macro


We’ve already been using VBA, but now I want to switch gears slightly
to show you how to use a macro someone else wrote—for example,
something you find on a webpage. For this example, I’ll use a macro I

108
wrote years ago to paste whatever’s on the clipboard as plain text, so
that it assumes the style of the surrounding text. If you were to do this
manually, the process would be: Choose Edit > Paste Special, select
Unformatted Text, and click OK. A macro can reduce all that to one key
combination!

To use a macro someone else has written:

1. Choose Tools > Macro > Macros.

2. Type a new macro name (we’ll use PastePlainText) and click Create.

3. In the window that opens, you’ll see a placeholder template for your
new macro, like so:

Sub PastePlainText()
'
' PTT Macro
'
'

End Sub

4. Paste or type the macro commands. For this example, enter the
following in the blank space before the End Sub line:

Selection.PasteSpecial Link:=False, _
DataType:=wdPasteText, Placement:=wdInLine, _
DisplayAsIcon:=False

109
5. Your final macro should look like this:

Sub PastePlainText()
'
' PTT Macro
'
'
Selection.PasteSpecial Link:=False, _
DataType:=wdPasteText, Placement:=wdInLine, _
DisplayAsIcon:=False
End Sub

6. If you like, you can remove the lines starting with an apostrophe;
those are comment lines that don’t affect the macro’s function.

Your macro is now ready to run. You can run it using Tools > Macro >
Macros, or assign a keyboard shortcut to your macro (such as ⌘-Shift-
V) following the instructions in Assign a Keyboard Shortcut to a VBA
Macro.

Note: I said I “wrote” this macro years ago, but, in fact, I cheated—I
recorded myself following the steps I spelled out a moment ago, and
this macro is what I got!

Find Sample VBA Macros


You should be able to turn up all sorts of VBA macros with a few web
searches. Here are a few resources to get you started:

• Excel Macro Examples & Free Downloads at Chandoo.org

• VBA Code Excel Examples at Analysistabs

• Word: Sample Macros, VBA Codes at MSDN Blogs

110
Learn More about VBA
To get help writing and editing VBA macros, try these sites:

• Microsoft’s Office 2016 for Mac pages Create, run, edit, or delete a
macro, Automate tasks with the Macro Recorder (for Excel), and
Create a macro in PowerPoint

• Microsoft’s Getting Started with VBA in Office for Mac 2011 page
(which still largely applies to later versions of Office)

Automate Nisus Writer Pro


Nisus Writer Pro is a powerful yet easy-to-use word processor. Wait,
did I call it a word processor? Oh, it’s much more than a word proces-
sor; I like to think of it as a Programmable Everything Tool. I explain
my history with Nisus (the product and the company) and why I’m so
enamored of this app in my Macworld article Tools of the trade: Why I
prefer Nisus Writer. For anyone who works with words, it’s an extraor-
dinarily flexible tool—and capable enough that Take Control Books has
left behind both Word and Pages and now creates ebooks (including
this one) exclusively in Nisus Writer Pro. With the coupon at the end of
this book, you can buy Nisus Writer Pro at a 25% discount.

One of the reasons I like Nisus Writer Pro so much is that it’s chock full
of automation features that make my writing faster and more efficient.
In this chapter I want to look at three of them: macros, multi-key
shortcuts, and automatic numbers and cross-references.

Run Macros in Nisus Writer Pro


As in other apps, macros in Nisus Writer Pro let you perform an action,
or a list of actions, with a menu command or keyboard shortcut. But
Nisus Writer Pro macros can do much more than run sequences of
commands; they can interact with files and folders on your Mac, ask
for user input, make decisions based on complex logic, and access
capabilities in the app that don’t appear anywhere in the visible user
interface. In other words, macros let you create entirely new features.

111
Nisus Writer Pro includes over 50 preinstalled macros on the Macro
menu (or its submenus). Choose any macro name to run it. Some
macros assume you have text selected first; if you try to run a macro
and it won’t work in the current context, it’ll either beep or display an
error message.

Here are a few you might try:

• Macro > Calculation > Mortgage Calculator: Fill in the


blanks to calculate your monthly payment.

• Macro > Document > Create Word Frequency List: This


creates a new document listing every word in the existing document
(or selection) along with a count of how many times it appeared.

• Macro > Editing > Quote Selection: Select some text and run
this macro to put quotation marks around it.

Take Control authors and editors have lots of specialized macros that
aid in our workflow, such as:

• Converting documents that use our highly customized styles into


Markdown formatting, which we then use to create the EPUB
versions of our books

• Inserting or formatting tips and notes

• Turning selected text into a cross-reference to a bookmark else-


where in the document

• Checking for common errors, such as graphics with problematic


names or extra spaces between words

If you’d like to find more macros you can install and run yourself, visit
Nisus Software’s Nisus Writer Pro Macros forum. (That’s also a good
place to find tips on writing your own macros.)

112
Create Macros in Nisus Writer Pro
To make your own macro in Nisus Writer Pro, follow these steps:

1. Choose Macro > New Macro. A new window (which looks just like a
regular document window) opens.

2. Type or paste the text of your macro. For illustration purposes, try
this:

prompt "Hello, world!"

3. Choose Macro > Save as Macro. Give your macro a name (such as
Hello) and choose a location. The ideal destination is your default
Macros folder, and you can choose or change that location using the
Macro > Choose Macros Folder. (If you’re uncertain which folder is
currently the default for saving macros, choose Macro > Show
Macros Folder in Finder, and that window opens.) If you save a
macro in the default Macros folder, it will automatically appear on
the Macro menu; if you save it anywhere else, you’ll have to go
through extra steps (which I don’t cover here).

Now, to run your macro, choose its name from the Macro menu:
Macro > Hello (or whatever you named it). You should see a little
dialog with the text “Hello, world!” Click OK to dismiss it.

If you want to view or edit a macro that’s already in the Macro menu,
the easiest way to do so is to hold down the ⌘ key while choosing the
macro from the menu—instead of running, it opens in a new window.
You can edit it there; after you save it, choosing the macro name from
the Macro menu in the normal way runs your updated version.

Tip: You can, of course, assign keyboard shortcuts to macros too. I


cover that just ahead, in Use Multi-Key Shortcuts in Nisus Writer Pro.

I gave you a one-line example macro, but what else can you put in a
macro? I’m glad you asked. Let me begin with the easiest approach to
writing your own macros.

113
Simple Macros
First, the bad news: unlike Microsoft Office, Nisus Writer Pro has no
recording capability—it can’t watch what you do and make a macro out
of that for you. But now, the good news: it’s way easier to write macros
for Nisus Writer Pro than for Word!

How easy? For the simplest things, like running menu commands, you
just type a command (as it appears on a menu) on a line by itself. If the
command includes an ellipsis (…), you can leave that off.

So, here’s a macro that turns the selected text bold, makes it 18 points,
and then copies it to the clipboard:

bold
18
copy

And that’s a complete macro, by the way—no brackets, semicolons,


declarations, funky names, or obscure codes. Case doesn’t matter.
(Spelling does matter!) Great, right?

Tip: When trying the macros from this book in Nisus Writer Pro,
either retype them or paste them by choosing Edit > Paste > Paste
Text Only (⌘-Shift-V). If you paste styled text into a macro, you
might encounter inscrutable error messages.

A macro can do lots of things that aren’t merely menu commands, too.
Want it to type the text “Hello, world!”? Do it like this:

type text "Hello world!"

Find all instances of the word Apple?

find all "Apple"

Set the line height to exactly 17 points?

set fixed line height 17

You can construct a macro with dozens or hundreds of commands like


this, one after the other, and it will execute them all with a single click.

114
I gave find all "Apple" as an example, but one of the most useful
things you can do in a macro is automate more elaborate find-and-
replace procedures—or a series of them. Nisus Writer Pro, like a few
other apps mentioned in this book, lets you use a pattern-matching
system known as regular expressions for finding and replacing text. (It
can take those expressions even further by applying styles to portions
of the expressions—a highly unusual feature.)

Any type of find or replace operation can go in a macro. For example,


this macro line finds any sequence of two or more return characters
and replaces it with one:

find and replace '\\n\\n+', '\\n', 'Ea'

Note: The letters E and a at the end tell the macro to perform the
find and replace with two special options—using regular expressions,
or PowerFind Pro, as Nisus Writer Pro calls them (E), and replacing all
the occurrences in the document (a). Those special characters are
case-sensitive.

This one finds any sequence of two capitalized words and underlines
just the first one:

find and replace '([A-Z][a-z]+)( [A-Z][a-z]+)', '\\1\\2', 'Ea-iU'

Note: The -i at the end means “case-sensitive search”; the U means


“attribute-sensitive replacement.”

Complex Macros
It’s easy to make a macro that executes a series of simple commands,
but you may want to do fancier things. You may want to use variables,
arrays, objects, functions, loops, if/then/else conditionals, mathemati-
cal functions, string manipulation, and other sorts of things you’d
normally find in a “real” programming language. All that, and much
more, is well within the purview of Nisus Writer Pro macros too!

I’ve written many of these complex macros that involve serious pro-
gramming, and while I can say confidently that it’s not nearly as bad as
working in VBA or even AppleScript, it’s different. And the way you

115
construct the commands and routines to do these nifty things is far
from obvious.

Unfortunately, there’s not room here for me to get into the finer points
of the language. You can get some guidance from the Nisus Writer Pro
macro reference—choose Help > Macro Language Reference in Nisus
Writer. That document contains all (well, nearly all) of the commands
in the language, and a number of examples. But candidly, it wasn’t
written for the layperson. The macro language itself isn’t unduly
complicated, but the documentation makes it seem harder than it is.
Someone ought to write a better guide. Maybe one day, somebody will.

In the meantime, I recommend the same thing for learning Nisus


Writer Pro macros as I recommend elsewhere in this book for VBA and
AppleScript: start with things other people have written (including the
50+ macros included with Nisus Writer Pro), try modifying them a
little bit, and once you get the hang of that, start exploring new com-
mands and features.

Use Multi-Key Shortcuts in Nisus Writer


Pro
Nisus Writer Pro lets you assign a keyboard shortcut to any command,
including macros you create yourself. That isn’t unusual. What is
unusual, and extremely helpful, is that you’re not limited to modifier
keys and a single character (like ⌘-P or ⌘-Option-Shift-I). You can do
all that, but you can also have keyboard shortcuts that are sequences of
keys.

For example, there’s a menu command that capitalizes the first letter
of each selected word: Edit > Transform Text > To Capitalized. You
could assign ⌘-Control-Shift-C to it, but that’s hard to remember.
What’s easy to remember is ⌘-C-A-P. That is, hold down Command
while typing C, and then A, and then P. Cool, no?

Multi-key shortcuts are much easier to remember, because you can


build in more mnemonic clues. How about:

• Save As: ⌘-S-A

116
• Save As PDF: ⌘-P-D-F

• Replace and Find: ⌘-R-F

• Page Break: ⌘-P-B

• 12 (font size): ⌘-1-2

I’m sure you get the idea. Here’s how you set up a shortcut:

1. Go to Nisus Writer Pro > Settings/Preferences > Menu Keys (Fig-


ure 35).

Figure 35: Set up keyboard shortcuts here.

2. In the first column, select the menu where the command is found.

3. In the second column, select the command (or, if it’s not on the top
level of the menu, navigate through the submenus to select it).

Tip: You can also create menu keys for individual preference panes
by navigating to Nisus Writer Pro > Settings/Preferences > pane
name. I set up ⌘-M-K to take me directly to the Menu Keys pane!

117
4. Click in the field on the rightmost pane.

5. Press the keyboard combination or sequence you want to use. You


can include as many characters as you like: ⌘-C-A-P-I-T-A-L-I-Z-E
is valid. But realistically, that’s awkward to type—I suggest limiting
sequences to two or three characters, plus modifiers.

A shortcut must include Command, but it may include Shift, Op-


tion, and/or Control too. Any of these that you hold down while
entering a shortcut are selected, but you can also select or deselect
Shift, Option, or Control to add or remove it from the shortcut.

6. Click Set.

7. Repeat with any additional shortcuts you want to define. When


you’re done, click the red Close button. (Don’t press ⌘-W, because
Nisus Writer Pro will think you’re trying to assign that shortcut to
the current command!)

Keyboard shortcuts are available immediately.

Use Automatic Numbers and Cross-


References in Nisus Writer Pro
The final Nisus Writer Pro automation tool I want to mention com-
bines two features: automatic numbers and cross-references. I’ve used
both dozens of times in this book. Let me tell you why they’re great.
Nisus Writer Pro can automatically number almost anything—pages,
sections, lists (such as the seven steps just above), figure numbers (as
seen throughout this book), tables, and the like. These numbers are
variables that update themselves automatically. So, if I’m creating a list
that has six items (numbered 1–6) and I press Return to create a
seventh item, it’s numbered 7 automatically; if I insert, remove, or
reorder part of the list, all the numbers update themselves. Similarly, if
I use automatic numbering for figures, I can freely add, delete, or
rearrange figures without ever worrying that the figure numbers in the
captions will be out of order.

118
That part is useful but not terribly unusual; most word processors can
do something of the sort. Where it gets interesting is cross-references
to the automatic numbers. For instance, I might have a graphic that’s
labeled “Figure 12,” and near it I say, “see Figure 12.” I want that
reference to update automatically if, later on, that graphic turns out to
be Figure 15 instead. So instead of just typing the reference, I insert a
cross-reference to the text of that automatic number. As the figure
number itself changes, so does the textual cross-reference!
OK, I’m oversimplifying slightly. For performance reasons, Nisus
Writer doesn’t automatically update cross-references immediately
when their references change, though it does so when you open a
document, print it, add or update a table of contents, and at certain
other times. If cross-references ever appear to be out of date, you can
force an immediate update by choosing Tools > Automatic Content >
Update All Stale Content. It goes without saying that you can and
should assign a keyboard shortcut to that command! Mine is ⌘-USC.

Note: Nisus Writer Pro can do this trick with lots of things, not just
automatic numbers. Any time text in one part of your document
changes, cross-references to that text elsewhere can update them-
selves. (That’s what I’ve done with all the links in this book to other
topics—if I rename a heading, the text of the link updates too.)

A full explanation of how to use automatic numbering and cross-


references in Nisus Writer Pro would take many pages, so I’ll walk you
through just one example:

1. Begin by creating a new list style, just for figure numbers. In a Nisus
Writer Pro document, choose Format > Lists > Edit List Styles.

2. Click the plus button at the bottom and choose List Style from
the pop-up menu. Name it Figures, leave the Kind set to Numbered,
and click Create.

3. In the sample text area on the right side of the window, select
Level 1. Then, in the Lists palette (if you don’t see it, choose
Window > Palettes > List), click in the Before Text field and type

119
Figure followed by a space. In the After Text field, type a colon (:)
followed by another space (Figure 36).

Figure 36: Your list style definition should look something like this.

4. Choose View > Page View to return to editing your document.

5. Insert a graphic (or just type some text, pretending that it’s a graph-
ic) followed by Return. Type a caption in the paragraph beneath
that line, such as This is the caption.

6. With your insertion point still in the caption paragraph, choose


Format > Lists > Figures to apply the Figures list style. In so doing,
the caption will be preceded by “Figure 1: ”.

7. Repeat steps 5 and 6 a few times, so you have three or four num-
bered figures. (If you press Return at the end of a list paragraph,
Nisus Writer Pro assumes you want that next paragraph to be in list

120
style too. You can override this by choosing Format > Lists > Use
None, or by applying a paragraph style, such as Normal.)

8. Somewhere else in your document, in an ordinary paragraph, type


See and a space. Choose Insert > Cross Reference. Make sure the
Insert Reference To pop-up menu says List Item, the Display Text
pop-up menu says List Item Number, and the two checkboxes are
deselected. Select Figure 2 in the list and click Insert.

Your text should now say “See Figure 2”.

9. Now make a change to your document so that Figure 2’s number


changes—for example, remove the caption for Figure 1, or add
another captioned figure before Figure 2.

You should see that the caption’s figure number updates itself, and the
reference to that caption in the text updates itself to match! (And, if
that doesn’t happen immediately, remember that you can force an
update with Tools > Automatic Content > Update All Stale Content.)

Note: What I just presented was a distinctly oversimplified version of


what we do for Take Control books, but it should demonstrate the
basic principles.

Discover Other Internally Scriptable


Apps
You’ve seen that Microsoft Office and Nisus Writer Pro have built-in
scripting languages, in addition to being controllable by AppleScript
and external macro utilities. But you may be wondering: is that it? Are
there no other Mac apps that have internal macro or automation
features? Indeed there are others! Here are a few prominent examples:

• Adobe Acrobat Pro and Photoshop: Both of these apps let users
create actions, which are basically macros—sequences of predefined
steps that alter a document or image in some way. You can also
install actions other people have written, some of which are fantas-
tically sophisticated.
121
• BBEdit: This splendid plain-text editor, which is designed mainly
for programmers and web designers but has also found a following
among authors, has a couple of great automation features. Text
factories are sequences of actions (such as find-and-replace–based
on regular expressions, natch; sorting lines; changing case; and
running shell scripts or AppleScripts) that you can save and run
repeatedly with a couple of clicks. BBEdit also has a Text > Apply
Text Filter submenu, which lists not only your text factories but also
individual Automator workflows, AppleScripts, and shell scripts
that can process and modify your text.

Tip: See Adam Engst’s TidBITS article BBEdit 13 Simplifies Pattern-


Based Searching for an introduction to searching with regular expres-
sions in BBEdit.

• FileMaker: This user-friendly relational database from Apple sub-


sidiary Claris International Inc. is deeply scriptable. You can use its
own extensive built-in scripting language, or AppleScript, or the two
in combination to take nearly any action when a button is pressed, a
menu command is selected, or any of half a dozen other triggers
occurs. Scripts can include complex logic, mathematical calcula-
tions, and numerous types of data manipulation.

• Google Workspace: This web-based productivity suite, formerly


known as G Suite, includes apps for editing for documents (Google
Docs—somewhat like Word), spreadsheets (Google Sheets—some-
what like Excel), and presentations (Google Slides—somewhat like
PowerPoint), among other tools. Lots of people do their day-to-day
document editing with Google’s apps in a browser. To automate
tasks in these apps, you use a scripting language called Google Apps
Script. It’s based on JavaScript, and basically amounts to VBA for
Google apps. But it’s even better than VBA in that it can add custom
menus, dialogs, and sidebars to G Suite apps, interact with other
Google services (such as AdSense and Google Drive), and quite a bit
more.

• Logic Pro X: Apple’s professional audio recording software lets you


create multitrack recordings of real and virtual instruments and

122
vocals, add effects, and mix audio every which way. It can memorize
all your changes in real time—adjustments to volume, panning,
equalization, effect levels, and other parameters for each individual
track—and repeat those changes every time you record or play back
your music.

• OmniGraffle, OmniOutliner, and OmniPlan: These fine apps by the


Omni Group use JavaScript for automation—and that works even in
their iOS versions. It’s such an innovative automation technique
that I’ve devoted a whole chapter to it. See Use Omni Automation.

• Panorama X: Another database app, even older than FileMaker Pro,


Panorama was designed for speed and flexibility. In much the same
way that Nisus Writer Pro is a programmable word processor,
Panorama is a programmable database—in fact, it’s a complete
development environment. You can control every aspect of its
operation and create enormously complex applications using its
built-in programming language; with scripts written in Perl, Ruby,
Python, PHP, or AppleScript; or with shell scripts. (Indeed, large
portions of Panorama were written in Panorama’s programming
language itself.)

Among other tasks, I use Panorama for tracking royalties for Take
Control authors. It’s an insanely powerful and flexible tool that, over
time, has enabled me to automate some of the most tedious parts of
my job. I can’t say enough good things about it.

123
Automate Email
Probably 90% of the time I spend using my Mac involves one of four
apps: a text editor, a word processor (I am an author, after all), a web
browser, and an email client. I send and receive large quantities of
email, and I use email far more frequently than phone calls or instant
messaging—maybe even more than speaking. It’s my main means of
communication.

Because my incoming and outgoing email volume is so high, I can’t


bear to spend any more time or effort than is absolutely necessary on
filing or searching for messages. So I’ve thought long and hard about
how to automate as much of that process as possible—while still
ensuring that important messages never slip through the cracks.

One of my key strategies is to use rules (sometimes referred to as


filters) to process messages as they come in. Each rule looks for certain
conditions (criteria such as a sender, subject, or words in the message
body), and then takes one or more actions whenever a match is found.
For example, the rule might move the message into a certain mailbox,
send an automatic reply, or delete the message.

If you’re trying to keep your inbox under control, rules are one of the
most powerful tools available. Because I presort my email with rules,
tons of messages that don’t require immediate attention never reach
my inbox at all; instead, they’re safely shunted to other mailboxes
where I can review them at my convenience. Creating a good set of
rules requires a bit of thought and effort, but once you’ve done that,
those rules operate invisibly in the background.

Rules are a very powerful organizational aid, but making them is just
one aspect of automating email. You may also want to simplify the
manual filing of messages that aren’t picked up by rules, add plugins
that automate various other email actions, or use smart mailboxes as
search shortcuts. I cover all those activities in this chapter.

124
Use Server-Based Rules
Rules can operate either in your email client (such as Apple Mail) or
directly on your incoming mail server. The huge advantage to server-
based rules is that they can presort messages before you see them, even
if your Mac email client isn’t running. That greatly reduces the amount
of mail you need to deal with on your iPhone or iPad.

I recommend starting with server-based rules if possible and then


using rules in your email client for the actions you can’t accomplish on
the server, like running user-defined AppleScripts on matching mes-
sages or moving messages to mailboxes in other accounts.

Check with your email provider to see whether it offers server-side


rules or filters, and if so, what the procedure is to configure them.
Here’s how to get started with iCloud and Gmail:

• iCloud: Log in to your account at iCloud.com. Click Mail, and then


click the gear icon in the lower-left corner and choose Rules
from the pop-up menu. Click Add a Rule to configure your first rule.

• Gmail: Log in to your Gmail account (using this link or whichever


URL you normally use for a Google Apps account with a custom
domain). From the Settings pop-up menu at the top of the page,
choose Settings, and then click Filters and Blocked Addresses. Click
“Create a new filter” to begin setting up a custom filter.

Although the details vary from one provider to the next, rules always
contain one or more conditions (things to search for) and then, when
there’s a match, perform one or more actions. For example, look for
any message from a certain address (say, a company’s PR department)
and file it in a Newsletters mailbox.

If your email provider doesn’t offer server-based rules, or if its condi-


tions or actions don’t meet your needs, you can move on to rules in
your email client. If Mail is your preferred client, that’s just one of the
ways you can automate your email.

125
Tip: A service called SaneBox will, for a monthly fee, perform an
automated analysis of your incoming messages, determine what’s
likely to be less important to you, and move it out of your inbox
(providing only a brief summary). It can do other tricks too, such as
providing server-based rules—even if your email provider doesn’t
offer them—and automatically moving attachments to cloud storage
such as Dropbox. Although SaneBox doesn’t fit my model of email
management, many people find it immensely helpful.

Automate Apple Mail


Apple Mail is my email client of choice, and as I mentioned, I go to
great lengths to automate my email. In this chapter, I’ll cover my three
main techniques: using rules to pre-sort my messages, using plugins to
file and otherwise work with them once they’re in my inbox, and using
smart mailboxes for searching. This information largely comes from
my book Take Control of Apple Mail, which has far more detail—not
just about automation but also about using email more effectively,
troubleshooting problems, and becoming a better correspondent.

Manage Incoming Apple Mail with Rules


Whether or not you use server-based rules, you might want to set up
rules within Mail. They work essentially the same way—sorting, delet-
ing, replying to, or otherwise processing incoming messages. But they
can do a few things server-based rules can’t do (such as moving a
message to a different account and running an AppleScript). And, if
you can’t use server-based rules, Mail’s rules are the best way to
manage the flow of incoming messages.

Tip: For help writing an AppleScript that will be used in a Mail rule,
open Script Editor (in /Applications/Utilities) and choose File >
New from Template > Mail > Mail Rule Action. That’ll open a template
with example code to get you started.

126
Create a Rule
To create a basic rule, follow these steps:

1. Go to Mail > Settings/Preferences > Rules and click Add Rule.

A dialog appears showing the condition(s) the rule checks for and
the action(s) Mail takes if the conditions match (Figure 37).

Figure 37: Use this dialog to specify the condition(s) and action(s)
for your Mail rule.

2. Enter a name for the rule in the Description field.

3. Create a condition. Start by choosing something from the left-hand


pop-up menu in this area. Depending on what you choose, you may
now see a second pop-up menu, a text field, or both. Here are some
examples of completed conditions:

[From] [Contains] apple.com

[Subject] [Begins with] Take Control

[Date Sent] [Is Less Than] 3 days old

[Message Content] [Does not contain] Sierra

4. From the provided pop-up menus, choose the action you want the
rule to perform on a message if (and only if) it matches the condi-
tion you just specified. (Just ahead I explain how to handle rules
that include multiple actions.)

Here are some examples:


[Move Message] to mailbox: [Filed]

127
[Set Color of Message] [of background] [Blue]

[Reply to Message] (Click the button and fill in your stock reply)

[Mark as Read]

If you use a rule to move a message, choose your target mailbox


carefully. In general, unless you mean to specifically archive the
message to a local mailbox, you’ll want to move it to a server-based
mailbox—most likely in the same account—so the message will be
available on all your iOS/iPadOS devices and other Macs.

5. Click OK.
An alert appears, asking if you want to apply your rules (including
the one you just created) to messages in selected mailboxes.
6. Click Apply or Don’t Apply, as you prefer. I generally suggest click-
ing Don’t Apply, because applying new rules to messages in open
mailboxes can have unexpected and potentially unpleasant results.
7. If you’re finished creating rules, close the Preferences window.
Your new rule now checks all incoming messages for matches and
performs the actions on them that you set.

Rule Examples
One of the most common uses for rules is to process messages that
follow predictable patterns. If you find yourself filing, flagging, or
deleting a certain type of message at least once a week, you can save
time and effort by setting up a rule to do it for you. Examples are
mailing lists, utility bills, bank statements, newsletters, travel discount
offers, and jokes forwarded by friends or family members.

Here are a few rules I use:

TidBITS issues:
If Any of the following conditions are met:

[From] [Contains] [email protected]

128
Perform the following actions:

[Move Message] to mailbox: [Lists]

Any public Apple mailing list:


If Any of the following conditions are met:

[From] [Contains] @lists.apple.com

[Cc] [Contains] @lists.apple.com

Perform the following actions:

[Move Message] to mailbox: [Lists]

Feedback about this book:


If Any of the following conditions are met:

[Subject] [Is] Take Control of Automating Your Mac

Perform the following actions:

[Move Message] to mailbox: [Take Control Feedback]

Tip: To ensure that a message matched by a given rule isn’t also


processed by other rules, add the Stop Evaluating Rules action as the
final action for any rule. Doing this improves Mail’s performance and
avoids potential rule conflicts.

Mail applies rules automatically to messages as they are delivered to


your inbox. Sounds about right, but there is a hitch. Mail does not
apply rules to messages that arrive in other mailboxes, even if the
messages are unread. That means if you have a server-based rule that
moves certain messages to your Family mailbox, those messages
bypass your inbox and therefore don’t get processed by Mail’s rules.

You can manually apply rules to selected messages, wherever they


reside, by choosing Message > Apply Rules. For example, you might
want Mail to use rules to re-sort messages that were moved into the
wrong mailbox by the server. However, note that that command
applies all your rules, not just a specific rule.

129
Automate Apple Mail with Extensions or
Plugins
For many years, developers were able to add features to Mail for
macOS by writing special apps called plugins. Plugins could be quite
powerful, altering the way Mail receives and sends messages, adding
useful new interface elements and menu commands, and remedying
missing or poorly implemented features.

Note: Much of the text in this section was adapted from my book
Take Control of Apple Mail.

Apple never seemed to love plugins, for whatever reason, offering only
grudging support. Then, with Monterey, Apple announced an entirely
new architecture for third parties to interact with Mail: extensions,
which developers can create using a framework called MailKit. (As a
user, it’s unlikely you encounter that term.) Unlike plugins, Apple
embraced extensions and gives them explicit approval. Sadly, exten-
sions are more limited than plugins, preventing many types of func-
tionality available in third-party plugins, such as adding tags to mes-
sages, applying rules to outgoing messages, and changing signatures.

Starting with macOS 14 Sonoma, however, Mail no longer supports


plugins at all: extensions are the only way developers can add features
to Mail or alter its behavior. Some plugin developers were able to
retool their software to function as extensions, while others were not.

Warning! While you can use both plugins and extensions in Mon-
terey and Ventura, any plugins you had installed under Ventura or
earlier no longer function once you upgrade to Sonoma; you must
replace them with extensions or live without those features.

Extensions are packaged as full, standalone apps that use background


processes to talk to Mail. After installing and opening an app that
provides an extension, enable it by going to Mail > Settings/Prefer-
ences > Extensions and selecting the extension’s checkbox (Figure
38); confirm by clicking Turn On. Then switch back to the standalone

130
app associated with the extension and configure any additional set-
tings it may offer.

Figure 38: Enable extensions on the Extensions pane of Mail Set-


tings/Preferences.

Here are a few examples of Mail add-ons that are packaged as exten-
sions; some are also available as plugins for earlier versions of Mail:

• Email Filing Assistant: Email Filing Assistant (EFA) analyzes


your stored messages by subject, sender, recipients, mailbox, and
other criteria. Then, when you later select one or more messages
and invoke EFA, it intelligently recommends the mailboxes where
the message most likely belongs. As you continue to use the app,
accepting or modifying its suggestions, it learns your patterns and
improves its suggestions. It also supports filing outgoing messages.
EFA costs $5.99.

• Mailbutler: Mailbutler (by the company of the same name, a Ger-


man developer formerly known as Feingeist) started as an amalga-
mation of several independent plugins. One of those was Cargo-

131
Lifter, which automatically uploaded attachments to cloud storage,
replacing them with a link, much like Mail Drop does but with
vastly greater flexibility. Although that capability sadly no longer
exists in the current version, Mailbutler still offers the following
wide array of features:

‣ Track whether recipients have opened your messages and/or


clicked links in them (with limitations)

‣ Attach notes and to-do items to messages

‣ Snooze incoming messages, removing them from your Inbox and


returning them later when you have time to deal with them

‣ Add tags to messages and contacts to help you organize them

‣ Use boilerplate templates for frequent replies

‣ Display avatar images of your correspondents

‣ Provide greater customization of signatures than Mail’s built-in


capabilities

‣ Integrate with Evernote, Google (Tasks and Contacts), Microsoft


(Microsoft To-Do, OneNote, and Outlook Contacts), Slack,
Trello, and other cloud-based services

‣ Share templates, signatures, contacts, and other Mailbutler data


within a team

‣ Use AI tools to help you compose, reply to, and summarize


messages

It also offers the following features that are similar to capabilities


added to Apple Mail in Ventura (albeit making it that much less
attractive to people using newer versions of Mail):

‣ Schedule messages for later delivery

‣ Remind you to follow up with a correspondent if you don’t


receive a reply to your message within a configurable period of
time

132
‣ Undo sending a message within a short period of time

Mailbutler offers several pricing tiers, starting with a Tracking plan


($4.95 per month) that includes only the tracking feature, while
higher-priced Professional, Smart, and Business plans provide
access to more features.

• SpamSieve: If you find that Mail’s built-in Junk Mail filter makes
too many mistakes, even after training, and server-side filtering is
unavailable (or no more successful), SpamSieve is the tool you
want. I’ve tried a bunch of spam filters for Mail, and SpamSieve is
by far my favorite. I’ve relied on it for many years, and although it
isn’t perfect, it does a much better job of learning as you use it than
Mail’s built-in filter does. SpamSieve costs $39.99.

The Once and Future SmallCubed Suite of Mail Helpers


One plugin I described in detail in earlier versions of this book that
couldn’t be transmuted into an extension is SmallCubed Software’s
MailSuite, which incorporated four modules: Mail Act-On, for filing
messages from the keyboard, scheduling sending, and more; MailT-
ags, for applying user-defined tags and other metadata; Mail Per-
spectives, for creating new, customizable views in Mail; and SigPro,
for adding dynamic signatures. Because it contained features impos-
sible to provide via an extension, it’s no longer being offered for
sale—even to people using versions of macOS older than Sonoma.
However, this is not the end of Mail Act-On, MailTags, Mail Perspec-
tives, and SigPro! SmallCubed Software is nearing completion in early
2024 of a new email app called MailMaven that’s intended to offer all
the features of Mail plus the MailSuite plugins (and quite a few other
extras). I have been working with the SmallCubed team on this app
for quite some time—testing, consulting, and offering design input.
When it’s finished, I’ll tell you all about it in Take Control of Mail-
Maven. (Yes, really!)

Tip: Mail lets you define signatures that appear at the bottom of each
message (see Mail > Preferences > Signatures). Although Mail
provides a decent level of customization, it doesn’t approach what
you can get if you Use a Third-Party Text Expansion Utility instead.

133
Search Faster with Smart Mailboxes
Back in Create and Use Smart Containers, I explained what smart
mailboxes are (basically, saved searches) and how to create them. If
you click a smart mailbox icon, it should initially display exactly the
same messages as the search you used to create it. As you receive and
delete messages that meet your criteria, the list will change.

Here are my favorite suggestions for making smart mailboxes:

• Show all correspondence with a specific person or group:


Choose Any from the pop-up menu at the top. Add two conditions,
[From] and [Any Recipient], both of which include the other per-
son’s email address. (To show conversations with more than one
person, create a new Contacts group with all the names you want to
include, and instead of [From], choose [Sender Is a Member of
Group] [some-Address-Book-group]. Then add [Any Recipient]
conditions for each person in the group individually.)

Make sure you select Include Messages from Sent to pick up your
messages to this person. For even better results, choose View >
Organize by Conversation to display all your exchanges in a thread-
ed conversation.

• Display recent unread messages: If you use rules to move


messages into different mailboxes, you might enjoy seeing all your
unread messages—wherever they may be—in a single place. If you
like, limit these to messages received in the last day (or few days).

• Locate attachments in Sent mail: If you often send photos or


other large attachments, their copies in your Sent mailbox can take
up a lot of space, and you probably have the originals. Make a smart
mailbox with two conditions: [Contains Attachments] and [Message
is in Mailbox] [Sent]. From time to time, check this mailbox; to
remove attachments from these messages, select them and choose
Message > Remove Attachments.

• What to do if All and Any aren’t smart enough: If you use the
[Message is in Mailbox] condition, the contents of one smart
mailbox can depend on another smart mailbox. This is handy when
134
you have so complex a set of conditions that Any and All are too
limited. For example, you might have one smart mailbox that lists
messages from any (“Any”) of several friends, and another that lists
messages that are both in the first smart mailbox and (“All”)
marked as high priority.

• Look for group members: Use the [Sender is a Member of


Group] option to search for messages from people in one of your
Contacts groups. And yes, you can even refer to smart groups, so
that as your contacts’ information changes, the contents of the
smart mailbox track the automatic changes in smart group contents.

Automate Outlook Email with Rules


Whatever you may think of Microsoft in general or Office in particular,
Microsoft Outlook for Mac is a highly capable email client with exten-
sive automation capabilities. You can create rules much like those in
Apple Mail, but with a few key differences:

• Each incoming account type (Exchange, POP, and IMAP) has its
own distinct rules.

• You can also create rules that apply to outgoing messages. (In Mail
that requires a third-party plugin).

• In addition to rules that match Any and All conditions, you can
specify negative matches—“Unless any conditions are met” and
“Unless all conditions are met.”

• The conditions and actions available are somewhat different from


Mail’s, but the most crucial one, in my opinion, is that while
Outlook’s rules can match any header or metadata, they can’t search
the message body on incoming IMAP messages—only on messages
coming from POP and Exchange accounts.

To create a rule in Outlook:

1. Choose Tools > Rules.

2. Select an account type in the list on the left.

135
3. Click the plus button.

4. Enter the desired condition(s) and action(s), give the rule a name,
and click OK.

The rule begins working immediately.

Automate Other Email Apps


I’ve focused here on Mail and Outlook because of their popularity. But
lots of other Mac email clients contain rules and/or other automation
features, too, including:

• Airmail

• Inky

• MailMate

• MailMaven

• Mail Pilot

• Postbox

• Thunderbird

I refer you to the apps’ documentation to discover how to use their


respective automation features.

136
Automate the Web
You might not think of web browsing as an activity that requires
automation. You follow links, you read articles, watch cat videos,
maybe make the occasional purchase, but that’s all inherently manual,
right? After all, I don’t want my Mac to read Facebook posts for me or
play games behind my back.

But in fact, the web offers numerous opportunities for shortcuts and
simplification. For example, every time you’re asked to supply a
username and password, a credit card number, or a mailing address,
your Mac can do that for you—no typing (or memorizing) required.

Here’s another example: you keep checking a certain webpage—or


maybe a specific portion of a page—for changes. Maybe you’re waiting
for an announcement, a sale, or a product update, or maybe you’re
looking for news stories about your neighborhood. Repeatedly check-
ing a page for changes (whether once a day or several times a minute)
is exactly the sort of labor-saving task computers are good at.

And then, looking more generally at cloud services that have a web
presence, there are tons of opportunities for connecting things. Per-
haps you want to post photos to Facebook after they appear in a shared
Dropbox folder. Or save links from your favorite tweets to Instapaper.
Or see an alert in the evening if tomorrow’s weather forecast calls for
rain. All sorts of things that can occur in one cloud service can trigger
events in other cloud services—an area ripe for automation.

Log In Faster with iCloud Keychain


and Safari Autofill
Let’s begin with an easy way to automate filling out all those pesky web
forms, without the need for any extra software.

Note: This topic is adapted from my book Take Control of iCloud.

137
The Mac version of Safari (like nearly all web browsers) can automati-
cally fill in your contact information (name, address, phone number,
and so on), as well as usernames and passwords, on web forms. Safari
uses the Mac’s systemwide keychain mechanism to securely store the
portions of this data that aren’t already in your Contacts app.

iCloud Keychain, included in macOS and iOS/iPadOS, extends this


capability. It lets you sync a keychain across your Apple devices se-
curely via the cloud. The biggest benefit is that Safari for iOS/iPadOS
can autofill usernames and passwords that you stored in a keychain on
your Mac (and vice versa). But iCloud Keychain also includes:

• A strong password generator built into Safari (on all platforms)

• The capability to store, sync, and enter credit card information in


web forms

• Support for multiple sets of credentials per site

• A way to view and remove passwords within Safari

In addition, if you turn on iCloud Keychain, it automatically syncs the


settings for the accounts listed in the Internet Accounts pane of System
Settings/System Preferences on your Mac (including email accounts)
amongst your other Macs. This account syncing does not extend to
iOS/iPadOS devices.

Starting in macOS 13 Ventura and iOS 16/iPadOS 16, Apple added


support to Safari (and iCloud Keychain) for a new authentication
method called passkeys. A passkey uses a clever two-part encryption
system instead of passwords and second factors to prove your identity.
Once you set up a passkey for a site on one of your Apple devices
(which is much simpler than creating a new password), it syncs to all
the others too. Then, all you need to do to log in on that site is touch
the fingerprint sensor (on Macs and iOS/iPadOS devices with Touch
ID), scan your face (on iOS/iPadOS devices with Face ID), or enter
your iCloud Keychain password (everywhere else). The only problem is
that, at present, relatively few sites support passkeys—though that
number is increasing steadily, and it includes such major players as
Adobe, Amazon, Apple, Google, eBay, LinkedIn, and PayPal.

138
Note: You can read more about passkeys in this TidBITS article or in
my book Take Control of Your Passwords.

Enable and Configure iCloud Keychain


The short version of setting up iCloud Keychain is: in Ventura or later,
go to System Settings > Account Name > iCloud > Password & Key-
chain (Ventura or later) and turn on Sync this Mac, in Monterey or
earlier, go to System Preferences > Apple ID > iCloud (Monterey or
earlier), select the Keychain checkbox, and enter your Apple ID pass-
word if prompted. Repeat on your other devices. However, unlike most
iCloud features, flipping a single switch isn’t all there is to it here; the
initial setup process is more involved. Also, the steps you follow with
whichever device you set up first will be different from the steps for
setting up all subsequent devices.

If you haven’t already set up iCloud Keychain, I encourage you to read


Apple’s article Set up iCloud Keychain for details.

One iCloud Keychain is enabled and syncing your data, you must next
configure Safari to use its features. Go to Safari > Settings/Prefer-
ences > AutoFill and make sure the checkboxes are selected for each
type of data you want to autofill—the two options relevant to iCloud
Keychain are “User names and passwords” and “Credit cards.” (If you
like, you can also select “Using information from my contacts” or
“Other forms”; I discuss these later.) Then click Passwords at the top
and, if the screen says “Safari passwords are locked,” fill in the pass-
word for your macOS user account and press Return.

Note: Mac users wanting to autofill passwords from iCloud Keychain


in browsers other than Safari will need Apple’s iCloud Passwords
extension, available for Google Chrome and Microsoft Edge (and most
browsers based on the same Chromium engine).

139
Autofill Secrets
Apple provides support for two intertwined account validation secrets:
passwords and verification codes. Nearly all sites require passwords
for login; an increasing number allow or require a verification code.

Autofill Passwords
After you load a login page for which you’ve already stored credentials
in your iCloud Keychain, you can do any of the following to fill your
credentials:

• Choose Edit > AutoFill Form

• Press ⌘-Shift-A

• Click in the Username or Password field and then click the creden-
tials you want to use on the pop-up menu that appears

Safari fills in the username and password fields for you—all you need
to do then is click or tap the Login button or its equivalent.

If you’ve stored more than one set of credentials for a site—for exam-
ple, if you have two different accounts for Microsoft or Google—first
delete the credentials Safari has autofilled, if any. You can then click in
the username field to display a pop-up menu (Figure 39). If the login
shown is not the one you want to use, click “Other Passwords for URL”
and then choose the one you want to fill in your credentials.

140
Figure 39: If you have multiple credentials for a site, click or
tap in the username field, then click the “Other Passwords for…”
option to display other matches.

If Safari autofills a set of credentials and it’s not what you want, delete
them and try clicking the username field again. If they still don’t
appear (for example, because the domain names don’t match exactly),
click Other Passwords. In the dialog that appears, locate the account
you want (manually or using the Search field). Select it and click Fill.

Some websites deliberately block browsers and password managers


from saving passwords you enter there, in a misguided attempt at
greater security. Safari can either accept or attempt to bypass any site’s
restrictions, but, unfortunately, you can’t control that behavior.

Autofill Verification Codes


Starting in macOS 10.15 Catalina, iOS/iPadOS 15, and Safari 15, Apple
also lets you work with a popular second-factor element for account
verification. Apple has built in the standard algorithm used for taking a
secret—known as a seed—offered up when you enroll your account for

141
second-factor authentication at a website or within an app and then
generating a unique time-based code that only a device possessing the
seed could provide.

Glenn Fleishman explains the process of setting up these codes (for


iOS, iPadOS, and macOS) in the TidBITS article Add Two-Factor
Codes to Password Entries in iOS 15, iPadOS 15, and Safari 15.

To use verification codes as part of logging in, after providing your user
name and password, tap a field or click in a field that prompts for the
code. Safari automatically generates a code tied to the website’s ad-
dress and lets you fill it in as Safari does for passwords.

If a code prompt doesn’t appear in macOS or as a QuickType bar entry


in iOS/iPadOS, you can use the same tools above to search for the
iCloud Keychain entry and copy the code from that entry to paste into
a webpage form field.

Store New Passwords


If you arrive at a login page for which iCloud Keychain does not yet
contain your credentials, enter them manually (or with a third-party
password manager) and log in. Safari should then display a prompt
asking if you want to save the password in your iCloud Keychain. Click
Save Password to store your credentials for that site.

Note: Again, if a site offers two-step verification via one-time codes,


see this article for instructions on setting that up.

If you already have credentials stored for the site and you want to store
an additional username/password combination, first delete the cre-
dentials Safari has autofilled. Then enter the new credentials, log in,
and click Save Password when prompted.

142
Generate a Random Password
When you’re asked to register on a website and create a new password,
iCloud Keychain can generate a unique and random one for you and
store it automatically. Follow these steps:

1. Make sure the Password field is completely empty.

2. Click in the field.

3. Click the key icon and choose Suggest New Password from the
pop-up menu.

4. Safari fills in a suggested password (highlighted in yellow), but


displays only the first few characters, along with the label “Strong
Password.” A popover with additional details may appear on its
own; if not, click the field to display it (Figure 40). (The same
password appears in a “verify” or “enter your password again” field,
if the website offers one.)

Figure 40: Click a suggested password to see this popover.

5. To use Safari’s suggested password (without even seeing the whole


thing), click Use Strong Password. To use an alternative password
without special characters, choose No Special Characters from the
Other Options pop-up menu. Or, to fill in your own password
instead (perhaps using a third-party password generator), choose
Choose My Own Password from the Other Options pop-up menu.

6. Fill in any remaining fields (such as Username) and submit the


form.

When you submit the form, Safari saves your credentials for the site
without any additional steps.
143
Store and Enter Credit Card Numbers
Credit cards work much like passwords—if you type or paste a credit
card number and its expiration date into blank fields in a web form
and submit it, Safari prompts you to save the credit card number in
your iCloud Keychain.
When it’s time to fill in a stored credit card number, click in the Credit
Card Number field and choose the desired credit card from the pop-up
menu. If you have more than one credit card stored, Safari displays a
pop-up menu from which you can choose the one you want to use, just
as when filling in your username and password on a site for which you
have multiple sets of credentials.

About Card Verification Numbers or CVVs


Your physical and virtual credit or debit cards each have a numeric
code generically called a CVV (card verification value). On a physical
card, it’s a three-digit number on its back for Discover, MasterCard,
and Visa; it’s a four-digit code printed on the front for American
Express. (Some card issuers instead refer to it as a CVC or card
verification code.) When making a purchase online, you nearly always
have to enter this code along with the card number and expiration
date. It’s considered a physical verification step. But, for a long time,
Safari couldn’t fill in these codes automatically, even as many third-
party password managers could.
This changed with the release of Big Sur and iOS 14/iPadOS 14, but
neither editor Glenn Fleishman nor I noticed it at the time. Now,
Safari can fill in the CVV, as long as you’ve recorded it. You may have
filled it in when you added a card to Apple Pay (in System Settings/
System Preferences > Wallet & Apple Pay). For cards not in Apple
Pay, you can add the CVV by going to Safari > Settings/Preferences >
AutoFill, clicking Edit next to “Credit cards,” selecting a card, and
filling in the Security Code field.

Autofill Other Data


I mentioned that you might want to enable Safari’s two other autofill
features in Safari > Settings/Preferences > AutoFill. The first, “Using
information from my contacts,” populates form fields with your con-
144
tact information when appropriate. The second, “Other forms,” does
the same thing for anything you’ve previously filled in on a form that
isn’t part of your credentials, credit card, or contact information—that
might include preferences, survey questions, or nearly anything else.

Tip: Pay attention when you use this feature, to make sure that it
doesn’t autofill unwanted data, such as an old coupon code in an
online shopping cart.

As you browse the web, if “Other forms” is selected, Safari remembers


everything you enter in a form field.

Later, if you want to fill that in on the same site—or if you want to fill
in your contact information—you have two choices:

• Choose Edit > AutoFill Form (⌘-Shift-A).

• Start typing your contact information in any form field. When Safari
sees that it matches corresponding information from your card in
Contacts, it pops up a little card icon labeled with your name. Click
this icon or press the ↓ key to select it, and then click AutoFill (or
press Return) to fill in the rest of the form.

Automate Web Logins with a Password


Manager
Although the combination of Safari and iCloud Keychain can simplify
entering most form data, you might consider (instead or in addition) a
third-party password manager. Why would you pay for something
that’s built into macOS and iOS/iPadOS? Well, third-party tools can do
several important things that iCloud Keychain can’t:

• Work on older versions of macOS, as well as non-Apple platforms


(Android, Windows, Linux) that you might also use

• Generate stronger random passwords to your exact specifications


(length, case, numbers, special characters, and so on)

145
• Autofill credentials in other macOS browsers (such as Google
Chrome and Firefox)

• Store and fill multiple sets of contact data (such as home and work)

• Store a broader range of information types, including software


licenses, passports, memberships, and reward programs

• Provide a friendlier interface for viewing and editing data than what
Apple offers

For all these reasons, although I use and appreciate iCloud Keychain, I
rely more heavily on a password manager called 1Password. It syncs all
my data amongst my Macs and iOS/iPadOS devices, as well as Win-
dows and Android devices. It has lots of useful organizational features.
And, it gives me a greater feeling of control over my passwords than
iCloud Keychain does.

When I navigate to a webpage at which I can enter my credentials, I


simply press the default keyboard shortcut ⌘-\, and 1Password fills
them in; I then press Return to submit the form—and even that step is
unnecessary in Safari. Piece of cake. (There are other ways to autofill
passwords in 1Password, but I generally stick with the method I’ve
used for years.) But that’s not all: 1Password can even fill passwords
into any app—not just browsers! I find that incredibly useful.

Tip: I like 1Password so much I wrote a book about it: Take Control
of 1Password. If you choose to use 1Password, you may find that
book helpful in getting up to speed.

However, 1Password is not by any means the only game in town. Other
third-party password managers that have most of the same features
(and thus, the same advantages over iCloud Keychain) include Dash-
lane, RoboForm, and Bitwarden. I’ve tried them all and would happily
recommend any of them.

Tip: To learn more about password security generally—including what


crucial steps you should take beyond simply using a password man-
ager—see my book Take Control of Your Passwords.

146
Tip: If you want to automate a series of operations on webpages,
such as logging in, filling in forms, and searching, you can use Key-
board Maestro (see Control Your Mac with Keyboard Maestro).

Automate Cloud Services


Hundreds of apps, sites, services, and other products proclaim their
connections to the cloud, even though it’s often unclear what “cloud”
means or what its benefits are. Mostly, a cloud is “internet-hosted
computers and storage that I don’t have to know about.”

More specifically, I use the term “cloud” to refer to storage, apps, and
other services made available over the internet as a replacement for
similar products that would otherwise run on local devices or require
managing resources on a server. Such services are provided by large,
distributed computer networks rather than individual servers, adding
another stratum to the cloud metaphor.

A consequence of this cloud craze is that you can end up with dozens of
accounts with cloud services that partially overlap in capabilities. Yet
for the most part, these services don’t communicate with each other.
The result is that you may end up spending a lot of time taking a file,
photo, or piece of information from one cloud service and moving or
posting it to another service.

Luckily, a few sites have emerged whose entire purpose is to connect


cloud services for you, automating the cloud so that useful things
happen in one service when something happens in another.

Let me give you some concrete examples of how multiple cloud ser-
vices can be connected and automated:

• Add something to the Reminders app (in macOS or iOS/iPadOS)


and it’s copied to an Evernote checklist.

• When someone tags you in a Facebook photo, download that photo


to your Dropbox.

147
• Post an Instagram photo and have it automatically sent to Flickr
too.

• Save all your incoming email attachments to your OneDrive.

• Send a thank-you note by email whenever someone endorses you on


LinkedIn.

Got the idea? Let’s look at three sites that let you do those sorts of
things.

IFTTT
IFTTT (for If This, Then That) is the best-known and most popular site
in this category. The name describes the basic concept: you create two-
part recipes called applets that say: If this happens (in one cloud
service), then do that (in a second service). These applet formulations
are a bit like email rules, except that, in their default representation
there’s always exactly one condition and one action—simple.

What services can you connect? Why, there several hundred of them,
which IFTTT refers to as “channels,” covering almost every major
cloud storage platform (Box, Dropbox, Google Drive, OneDrive…),
social network (Facebook, LinkedIn, Discord, Foursquare…), and
photo site (Flickr, Instagram, 500px…), plus iOS/iPadOS data (con-
tacts, location, notifications, photos, reminders), email, SMS, blog
platforms, news sites, home automation tools, and even things like the
date, time, and weather. The list is growing all the time.

IFTTT provides many prebuilt actions; you can also build your own,
use actions other people have created, or edit an existing applet to
meet your needs.) Here are a few examples of prebuilt actions:

• Back up your new Facebook photos to Google Drive.

• Post to Trello when a specific tag is added to an Evernote note.

• Whenever you add a new iOS/iPadOS contact, mark it in your


Google Calendar.

• Turn on your lights automatically as you arrive home.

148
• Automatically post a reminder to a Slack channel 15 minutes before
a calendar event starts.

• Get a mobile notification when your Whirlpool dryer cycle finishes.

As you see, applets are customizable to include things like time, date,
and location, among other attributes.

IFTTT is free for personal use. After signing up for an account, you
activate whichever channels you’re interested in by signing in to the
relevant accounts. Then you can choose from a prebuilt applet, or
concoct your own as follows:

1. Click your avatar in the upper-right corner and then click Create
from the pop-up menu.

2. Click the word This.

3. Click a trigger channel—where you look for the new piece of data
that will kick off the recipe.

4. Fill in any necessary information (the options vary by channel). For


example, if your trigger channel is Facebook, you click one or more
links to specify what particular activity in your Facebook account
you want to use (such as “You are tagged in a photo”). Then click
“Create trigger.”

5. Now click the word That.

6. Click an action channel—where the information from the trigger


channel will be sent. For example, you can click Email followed by
“Send me an email.”

7. Once again, specify any details necessary to complete the action,


such as whether you want to download a photo or have its URL
added to a text file.

8. Click “Create action.”

9. Finally, review your applet and click Finish.

That’s it! Your recipe now runs by itself, automatically taking the
action you specified when the trigger occurs.
149
Tip: For a great example of using IFTTT with iOS notifications (via
iCloud), read Ben Waldie’s Macworld article Power tools: Make events
on your Mac trigger iOS notifications.

If you need more power, however, you can turn to IFTTT Pro, a paid
service that lets you create applets with greater complexity. For exam-
ple, an applet can have not just one action but several—If this, then
that and that and that. And, the starting condition can run through a
filter that you write (using JavaScript) that overrides or skips actions
depending on certain variables.

Zapier
Unlike IFTTT, Zapier is designed primarily for business. As such, it
integrates with a much larger number of cloud apps and services,
including many that are strictly for enterprise use. Zapier refers to its
automations as Zaps. In the basic, free plan, you can create Zaps with
only two steps (a trigger and an action, just like IFTTT’s basic applets),
using a subset of the available cloud services. To access the full range
of services and multi-step Zaps, you’ll need a paid plan; prices start at
$19.99 per month.

If you need to automate business-related cloud services that IFTTT


doesn’t connect to, such as Infusionsoft, Zoho CRM, Basecamp, or
QuickBooks Online, Zapier is the tool to use. Some example Zaps:

• Add new WooCommerce orders to QuickBooks Online as cus-


tomers.

• Create Infusionsoft contacts for new successful sales in PayPal.

• Post new Basecamp 2 activity to Slack.

• Start or stop instances on Amazon EC2 on a daily schedule.

• Copy new Facebook Lead Ads leads into Zoho CRM as leads.

If those names don’t mean anything to you, don’t worry! You’re proba-
bly just not the target audience for Zapier, and IFTTT will likely be
more suitable for your needs.

150
Discover Other Web Automation Options
Connecting cloud services is fantastically useful, but sometimes you
may need something a bit simpler and more elegant. For example, you
might want to monitor the web (as a whole) for new pages on a topic of
interest, or monitor a specific page for changes.

Monitor the Web with Google Alerts


The web changes continuously, so Google is constantly updating its
massive index of the web to provide up-to-date search results. As a
result, a search you perform one day may yield completely different
results than it did yesterday. If you’d like to stay on top of a given
subject, you can use the free Google Alerts service to perform an
automated search every day (or even more frequently, if you like) and
send you any new results by email or a customized RSS feed.

To use Google Alerts, fill out a form with your search query (just as if
you were doing a regular Google search), click Show Options, and fill in
a few other details—most crucially, your email address (Figure 41).
The current results of your query appear beneath the form. Click
Create Alert, and you’re done—you’ll get the results automatically.

151
Figure 41: Create a Google Alert by filling out this form.

You can go back to the Google Alerts page whenever you like to add,
remove, or modify alerts. Ideas for Google Alerts:

• Google yourself and find out when people are talking about you.

• Follow rumors about hypothetical new Apple devices.

• Get the latest news on treatments for a medical condition a loved


one is experiencing.

• Search for discounts and deals on products you’re interested in.

• Keep tabs on your competition.

Use a Cloud Service to Monitor a Website


for Changes
In the online appendixes to my book about backing up a Mac, I have
tables listing the features of many backup apps and cloud services. This
information changes all the time, though. One way I keep that infor-
mation (more or less) up to date is by monitoring the pages that list
release notes or other version information for each of dozens of apps.

152
When a page changes, I check to see if the change is relevant to my
table, and if so, I update the table accordingly.

Needless to say, I don’t manually check dozens of webpages for


changes every day! Instead, I use a free service that checks for me and
sends me an email message if any monitored page has changed since
the last time it checked.

I’ve used two such services—WatchThatPage, which has a kind of


awkward and old-fashioned interface, but gets the job done; and
Visualping, which is more modern and customizable. Either way, the
process is dead simple: sign up for a free account, enter a URL, and
click a button to start monitoring it.

Tip: If you do use a service like this, do yourself a favor and set up a
rule in your email client (see Automate Email) to file all those change
reports into a special mailbox. They tend to accumulate over time!

Other reasons to monitor websites for changes:

• Watch for schedule changes, special events, and other announce-


ments from your child’s school.

• Find out the second any new Take Control book is published—even
if you’re not on our mailing list!

• Learn about new products or price drops in the Apple Store.

• Get updates on your favorite crowdfunding projects from Kick-


starter, Indiegogo, and the like.

153
Automate Backup and
Syncing
Anyone who has followed my writing for Macworld, TidBITS, or Take
Control Books over the last decade is undoubtedly aware of my passion
for good backups. I’ve written several books (including Take Control of
Backing Up Your Mac) and lots of articles on the topic, and I preach
about the importance of backups at every opportunity.

In this book, I’m not going to try to convince you to back up your Mac;
I’ll take for granted that you already know that’s a good idea. Instead, I
want to focus on automating backups. Believe it or not, there are still
people who back up important files by dragging them to another disk
once a day. Still others use backup software to do the job, but they back
up only when they remember to run that software.

My feeling is that if you don’t have hands-off backups, you’re doing it


wrong. Backups should happen all by themselves—whether once a
week or multiple times an hour—without any intervention. Not only
does it require extra effort to launch a backup app and click a button,
it’s an interruption—one you might put off if you’re too busy, or forget
about at a crucial moment right before losing data!

In this chapter, I discuss two backup scenarios: using Time Machine


and using a third-party tool that creates versioned backups. You may
not use both of these methods, but whichever one(s) you use, they
should be automated.

I also talk briefly about automating syncing between Macs. Although


that doesn’t count as backup in my book, many of the same assump-
tions apply—and you may even be able to use the same software for
both backups and syncing.

154
Run Backups Automatically with Time
Machine
Time Machine is the backup feature that Apple built into macOS. It’s
not necessarily the best backup tool, but it’s reasonably good. Most
importantly, it’s extremely easy to set up, making it the path of least
resistance for many users.

Time Machine ordinarily runs once an hour, backing up whatever has


changed or been added since the previous hourly run. This happens in
the background, with barely any visible clue. So, if you’ve set up Time
Machine already, and you’ve kept the default options, there’s nothing
more to see here—move along to the next topic.

If you haven’t already set up Time Machine and would like to—or if you
configured it but turned off automatic backups—keep reading.

Configure Time Machine in Ventura or


Later
To activate Time Machine in Ventura or later:

1. Go to System Settings > General > Time Machine.

2. Click Add Backup Disk.

A dialog appears (Figure 42), listing all local and network volumes
eligible to be a destination disk and the amount of free space on
each local disk.

155
Figure 42: Available local and network volumes appear in this
dialog; select the one you want to use and click Set Up Disk.

3. Select a volume and click Set Up Disk. Another dialog (Figure 43)
appears.

Figure 43: Set up encryption and a disk usage limit here.

156
4. Optionally, but strongly recommended, leave Encrypt Backup
selected, enter and repeat a password, and enter a hint. To forgo
encryption, turn off Encrypt Backup.

5. For local volumes only, a Disk Usage Limit control also appears. If
you’re content with using the entire volume for Time Machine
(preferable in most cases), leave Disk Usage Limit set to None.
However, if you want to use only a portion of the volume for Time
Machine and leave extra space for other uses, select Custom and use
the slider to specify the maximum amount of storage space your
Time Machine backups can occupy.

6. Click Done.

Normally, Time Machine then runs hourly, but you can change the
frequency if hourly backups are too frequent for your needs. To do this,
click the Options button in System Settings > General > Time Machine
and choose an option from the “Back up frequency” pop-up menu:
Manually, Automatically Every Hour (the default), Automatically
Every Day, or Automatically Every Week.

Configure Time Machine in Monterey or


Earlier
To activate Time Machine in Monterey or earlier:

1. Go to System Preferences > Time Machine.

2. Click Select Backup Disk.

A dialog appears (Figure 44), listing all local and network volumes
eligible to be a destination disk and the amount of free space on
each local disk.

157
Figure 44: Available local and network volumes appear in this dialog
(specifics vary according to your version of macOS); select the one
you want to use and click Use Disk.

3. Select a volume, and click Use Disk.

On the Time Machine preference pane, the Back Up Automatically


checkbox is selected, and a timer begins a 2-minute countdown before
your first backup begins.

At any point, you can select or deselect Back Up Automatically. When


it’s deselected, that means only that Time Machine doesn’t run auto-
matically; you can still run it manually, at any time, by clicking and
holding (or right-clicking) on the Time Machine Dock icon and choos-
ing Back Up Now, or by choosing Back Up Now from the Time Ma-
chine menu in the main menu bar. (If you don’t see the Time
Machine menu, you can enable it with the Show Time Machine in
Menu Bar checkbox in System Preferences > Time Machine.)

You can turn off Time Machine temporarily if need be, but please don’t
leave it off. Remember, backups are most valuable when they’re
automatic!

158
During each of Time Machine’s hourly runs, it backs up only the files
that have changed since its previous run. If an application stores its
data as a package (that is, a folder that looks like a file in the Finder),
Time Machine backs up only changed items within the package.
(Among many others, Photos, Keynote, GarageBand, and DEVONthink
use packages for their data.)

Restore Data with Time Machine


Once you have Time Machine set up and running, it normally does its
thing silently in the background, without intruding on your work. And
you can continue ignoring it until the time comes when you need to
restore something—a missing file or folder, or a previous version of a
file you still have.

If you notice that a file or folder is missing, or that you’ve accidentally


changed it and need an older version, follow these steps to retrieve an
item from your Time Machine backup:

1. In the Finder, make sure the window that contains the item you
want to restore (or the one that used to contain it, if it’s been delet-
ed) is frontmost—you can verify this by clicking anywhere in the
window.

2. Click the Time Machine icon in the Dock or choose Enter Time
Machine from the Time Machine menu.

The frontmost window moves to the center of the screen, and the
screen’s background changes to the “infinity mirror” display, with
copies of the window receding into the background (Figure 45).

159
Figure 45: Go “back in time” to a previous version of your data.

3. To locate the file or folder you want, do one of the following:

‣ Just to the right of the main window, click the top arrow (which
means backward in time). Time Machine zooms back to the most
recent backup in which that window’s contents were different.
Keep clicking to continue zooming back through previous ver-
sions of that window; click the bottom arrow to move forward in
time.

‣ Use the controls along the right edge of the screen to jump to a
particular backup. As you hover your pointer over the small
horizontal lines, they zoom in to display the date and (for recent
backups) time of the corresponding backup. Click any of these
lines to jump right to that version of the window. As you zoom
backward or forward in time, the date and time of the backup
you’re currently viewing is shown to the right of the main win-
dow.

4. Once you’ve selected the item you want to restore, decide whether
you want to restore it to its original location or somewhere else:

‣ Original location: Click the Restore button. Time Machine


immediately restores the selected item, and returns you to the

160
Finder. (Time Machine may prompt you to enter an administra-
tor password.) You can use this procedure even if you want to
restore an older version of a file but keep the current version.
After you click Restore and the Finder reappears, you’ll see an
alert asking whether you want to replace the existing file, keep
both copies, or keep the original (thus canceling the restoration).

‣ Different location: Right-click (or Control-click) the item and


choose Restore “File Name” To from the contextual menu, navi-
gate to the desired destination, and click Choose.

Note: In macOS 13 Ventura, restoring files to a different location


stopped working, and it is still broken as of macOS Sonoma 14.3. The
menu command appears, but you’re not given the opportunity to
choose a different location. I presume this is a bug, and have report-
ed it as such. Whether or when Apple fixes it is anyone’s guess.

If you decide against restoring any files, instead click the Cancel
button or press Esc.

Tip: For more details, including how to restore an entire disk with
Time Machine and how to restore data from within apps such as
Contacts and Mail, see my book Take Control of Backing Up Your Mac.

Create Hands-Off Versioned Backups


Whether or not you use Time Machine, you may use another product
to create versioned backups (that is, backups that store multiple
versions of each file). Dozens of apps can do this, including apps that
back up data to the cloud, apps that back up data to local devices, and
apps that do both.

In any case, I simply want to emphasize that if you use any such app,
you should be certain it’s configured to perform backups without any
manual effort.

Some apps back up files as soon as they change, or at least within an


hour or so—among these are apps such as Arq, Backblaze, and Dolly-

161
Drive. As long as that’s the case—and you haven’t disabled automatic
backups—you should be in good shape.

But many backup apps, especially those that have been around for
many years, run only on a schedule that you determine. Some apps can
run as often as once per minute; others can run no more frequently
than once per day. Apps that require scheduling include ChronoSync,
Intego Personal Backup, and QRecall, among others.

Note: Retrospect Desktop is a backup app that normally runs on a


schedule, but can be set to run whenever client machines are avail-
able using its Proactive Backup feature.

Follow the instructions that came with your backup app to schedule
backups. You can choose what frequency works best for you, which
should take into account how actively you modify files and how much
of an impact the backup app has on your system when it runs. For me,
once an hour is too infrequent, but even if you use your Mac only
casually, I suggest scheduling backups to run at least once a day.

What I use: Because I write so much about backups, I have more


backups than I need, so I wouldn’t tell you to do what I do. But I use
a combination of Time Machine and Backblaze for versioned backups,
plus several cloud syncing services that store multiple versions of
certain files.

Whither Bootable Duplicates?


In previous editions of this book, I had an additional topic here about
scheduling bootable duplicates. Unfortunately, although you can still
create a bootable duplicate in recent versions of macOS with a tool
such as Carbon Copy Cloner or SuperDuper!, a full bootable duplicate
can no longer be updated in an automated fashion. (You can, howev-
er, perform scheduled updates of just your user-created data.)
The full story of why that is, and why I no longer recommend
bootable duplicates at all for most people, is in Take Control of
Backing Up Your Mac. In any case, it’s no longer something I consider
a worthwhile Mac automation task.

162
Automate Mac-to-Mac Syncing
Do you use two or more Macs regularly? If not, skip ahead to the next
chapter. But if you do, you may find it useful to keep some or all of the
data in sync between Macs. I can say from experience that it’s far
better to automate this process than to do it manually!

I suggest thinking through two main questions:

First, is it desirable (or even possible) to keep all your personal files in
sync between two Macs?

If you have an iMac with 3 TB of storage and a MacBook Air with


128 GB, the answer is clearly no. Even if all your Macs have enough
space for all your files, you may not need or want to have all of them
everywhere. So, if the answer to this question is no, you’ll have to
figure out which subset of files to keep in sync. All things being equal,
it’s easiest if you can segregate all those files into a single folder or a
small number of folders.

You’ll notice, by the way, that I said personal files. You should never,
ever try to sync all files between two Macs—in particular, stay far away
from the top-level /System, /Library, and /Application folders, as well
as any hidden folders. Attempting to sync any of those can lead to
serious data corruption, including an inability to boot your Mac. So
whatever you choose to sync, make sure it’s not part of macOS.

Second, is it desirable (or even possible) to use a cloud service to sync


files between your Macs?

I’ll use Dropbox as an example. If it turned out that you had 800 GB of
data you wanted to keep in sync between two (or more) Macs, you
could purchase 2 TB of storage from Dropbox for about $120 a year.
Install Dropbox on your Macs, make sure all the files you want to sync
are in your Dropbox folder, wait for that initial upload to finish, and…
you’re done. You never have to run sync software or take any other
manual action; file changes propagate almost instantly. As a bonus, the
files in your Dropbox are also available on your mobile devices, and
can be shared easily with others.

163
What’s true of Dropbox is also true of numerous competing services—
Box, Google Drive, Microsoft OneDrive, SpiderOak One Backup,
SugarSync, and many more. They each have their own features, bene-
fits, and pricing, and you may prefer one over the others for any
number of reasons. But they all can perform the essential task of
syncing the contents of one or more folders across Macs automatically.

Then there’s iCloud Drive, which is built into macOS and iOS/iPadOS.
Superficially it works much like Dropbox, and it can keep whatever
files you store in it in sync between your Macs automatically. In fact,
iCloud Drive can optionally sync your Desktop and Documents folders
across your Macs too. That’s nice in theory, but I’ve found it to be
problematic in practice because of the extremely large and frequently
modified files I keep in those two folders. (You can disable this feature
in Ventura or later by going to System Settings > Account Name >
iCloud > iCloud Drive and turning off Desktop & Documents Folders;
in Monterey or earlier, go to System Preferences > Apple ID > iCloud,
click the Options button next to iCloud Drive, deselect the Desktop &
Documents Folders checkbox, and click Done. After doing this, select
iCloud Drive in the sidebar of any Finder window, open the Desktop
folder within it, and drag its contents to your desktop. Repeat with
your Documents folder.)

Tip: If you happen to choose iCloud Drive for cloud syncing, check
out Take Control of iCloud.

Of course, you may not want to sync files via the cloud, due to privacy
concerns, cost issues, available bandwidth, or the sheer volume of data.
If that’s the case, you might want to consider sync software such as:

• Resilio Sync Home: Based on the BitTorrent file sharing protocol,


Resilio Sync Home (formerly called BitTorrent Sync) functions
much like Dropbox, but without the cloud storage. You tell it which
folders you want to sync on each of your computers, and syncing
happens quickly, in the background, whenever files change. An iOS
app is available too.

164
• ChronoSync: This powerful and flexible app can sync files between
folders, volumes, or Macs in almost any way you can think of: one-
way, bidirectionally, with or without filters, and so on. (For Mac-to-
Mac syncing, you may want the add-on ChronoAgent app on one of
the Macs.) You can set up syncing to happen as frequently as once a
minute. ChronoSync can also create both versioned backups and
bootable duplicates, if you like, although it’s not quite as easy to use
as Time Machine or Backblaze.

What I use: I use Resilio Sync to keep a few of my key folders


(~/Documents, ~/Desktop, and ~/Downloads) in sync between my two
main Macs, and ChronoSync for more specialized tasks (such as
keeping certain folders in sync between two Mac servers I run). I also
use several cloud-based syncing services, most notably iCloud Drive
and Dropbox, to make a subset of my files—especially those I need to
share with other people—available across platforms.

165
Discover macOS
Automation Technologies
As we’ve seen so far in this book, macOS offers lots of ways to auto-
mate individual activities. But some automation tasks require apps to
talk to each other (or even to other computers), employ sophisticated
logic or user interaction, or perform specialized functions that are
unique to your situation. When simple tools aren’t up to the job, it’s
time to bring in the heavy hitters.

In the next four chapters, I talk about a subset of technologies that go


considerably deeper than things like keyboard shortcuts or text expan-
sion. These technologies—Automator, AppleScript, services, and shell
scripts—aren’t so much tools as platforms built into macOS that you
can use to create your own tools. As such, they’re more complex, but
also far more powerful. In this brief chapter, I introduce you to these
platforms and offer a bit of high-level advice about how to approach
them, especially if you’re a beginner.

I also offer a brief introduction to Using JavaScript for Automation.


Although I don’t cover JavaScript extensively in this book, it forms the
basis of the automation features in Omni products, which I discuss
later (see Use Omni Automation). And I say a few words about using
Apple’s newest programming language, Swift, as the basis for automat-
ing your Mac without writing new apps from scratch; see Using Swift
for Automation.

Apple’s Core Automation Technologies


There’s certainly some overlap among the technologies we cover next.
Indeed, I frequently have to flip a coin when choosing which of several
approaches I should use to solve a given problem.

166
So I’ve chosen to arrange these topics in order of what I consider least
to most intimidating. Get to know the ones earlier in the list first, and
as your knowledge and skills grow (or your needs outgrow the less-
intimidating tools), move on to the next:

• Services are plugins that add features for working with text, graph-
ics, and more to almost any app. macOS comes with a number of
built-in services, and many popular apps add their own. You can
also install standalone third-party services, or create your own using
Automator or other tools. See Use Services for Systemwide Short-
cuts.

• Shortcuts is an app that started out in iOS and iPadOS, and ap-
peared on the Mac for the first time in Monterey. Like Automator
(described next), it offers a simple, user-friendly way to wrap up
sequences of tasks into a single automation. It’s the hot new thing,
and in some ways, it’s even more powerful than Automator, but it’s
not quite ready to replace it yet. See Get Started with Shortcuts.

• Automator lets you construct multi-step operations called work-


flows using graphical building blocks rather than code. (It does,
however, let you incorporate code written in AppleScript, Java-
Script, and other scripting languages, if needed to solve particular
problems.) Automator makes it easy to experiment, and with a bit of
creativity, you can create quite powerful workflows that solve
everyday problems. See Get Started with Automator.

• AppleScript is a language you can use to write programs that do


all sorts of useful tasks on your Mac. It’s meant to resemble English,
but that’s perhaps an exaggeration; in any case, AppleScript is
certainly more difficult to use than Automator. Even so, AppleScript
is far more approachable than heavy-duty programming languages
like Swift and Objective-C, while still being quite capable. See Get
Started with AppleScript.

• Shell scripts run in the Terminal command-line utility, perform-


ing tasks using the Mac’s Unix underpinnings. Because shell scripts
have direct access to all the low-level Unix programs that make up
the core of macOS, they can solve problems that no other approach

167
can. But they do require you to interact with your Mac in a pure text
environment, which you may find confusing or off-putting if your
only experience using a computer has been through a graphical user
interface. See Script the Command Line with Shell Scripts.

Worried that this all sounds too complicated? Don’t be. I want to make
sure you understand this crucial concept up front:

You can use a service, shortcut, Automator workflow, AppleScript, or


shell script without knowing how to create one.

In fact, that’s precisely what I recommend. For each of the technolo-


gies in the following four chapters, I suggest the following process:

1. Learn how to locate, install, and use scripts or tools written by other
people.

2. Once you’re comfortable using them, try modifying them slightly.


That’s one of the easiest ways to learn how they work while also
customizing them to better meet your needs.

3. When you have time to tinker, start to create your own scripts/tools,
using the resources I recommend (and with other people’s work as a
guide).

But before I turn you loose on that stuff, I want to mention two other
important automation approaches that you should be aware of.

Using JavaScript for Automation


Apple makes it possible to use JavaScript as well as AppleScript for
scripting. To be precise, Apple’s implementation is called JavaScript
for Automation, or JXA. To oversimplify greatly, JXA means that you
can now do nearly any sort of automation task in JavaScript that would
previously have required AppleScript. You can even create your Mac
automation JavaScript code using the Script Editor app, just as you do
for AppleScript—all you have to do is choose JavaScript from the pop-
up menu just below the Record button in the upper-left corner of the
Script Editor window. (In fact, JXA is available throughout macOS;

168
you can use it for Mail rules, Calendar alarms, and anywhere else you
can use AppleScript.)

Why might you want to do this?

For one thing, lots more people know JavaScript than know Apple-
Script. If you already know a bit about JavaScript programming—for
example, from designing websites—you can now use that skill to
automate activities on your Mac, without having to learn a new (and,
let’s face it, rather quirky) programming language. All you need to
learn is how to reference the objects and methods you want to interact
with (most of which are similar to, if not identical to, the correspond-
ing AppleScript terms).

Tip: To learn the terminology for interacting with Mac apps using
JavaScript, open Script Editor, choose File > Open Dictionary, select
an app, and click Choose. Then, from the Language pop-up menu at
the top of the dictionary window, choose JavaScript instead of Apple-
Script.

JavaScript also lets you write code that can be used in both macOS and
iOS versions of certain apps (see Use Omni Automation). That usage
could plausibly extend to other developers’ apps in the future.

This book doesn’t cover JavaScript programming as such, but if you


already know how to write code in JavaScript, you can pretty much
follow everything I say later in Get Started with AppleScript and simply
replace the logic with JavaScript code. To learn more about automat-
ing your Mac with JavaScript, see:

• This 25-minute training video by Sal Soghoian

• Apple’s JavaScript for Automation Release Notes

• Getting Started with JavaScript for Automation on Yosemite, by


Alex Guyot at MacStories (which still applies to newer systems)

169
Using Swift for Automation
Since the introduction of Mac OS X, Objective-C has been the primary
language programmers used to create full-blown apps for macOS (and,
later, iOS, watchOS, and tvOS). In 2014, however, Apple debuted a
brand-new programming language called Swift, which was designed to
be more modern, easier to use, and less prone to certain kinds of errors
and bugs than Objective-C. In the years since, Swift has undergone
rapid development. It hasn’t yet completely replaced Objective-C (and
indeed, for some programming tasks, Objective-C is still the superior
choice), but it’s well on its way. Nearly any type of app can be written
entirely in Swift, and it’s clearly the future of programming as far as
Apple is concerned. There’s even a free app called Swift Playgrounds
(available for Mac and iPad) that teaches you how to code in Swift
using a game-like interface.

Ordinarily, Swift is written in Xcode, and compiled into an app before


it’s run. But what if you could use Swift in a manner somewhat analo-
gous to AppleScript or JavaScript to automate user-level activities on
your Mac, without all that overhead? Aside from solving your immedi-
ate automation problems, that could provide a useful environment in
which to learn the language.

In fact, I know of two ways to do just that:

• Keyboard Maestro, which I discuss extensively later on (see Control


Your Mac with Keyboard Maestro) lets you embed Swift scripts as
actions in your macros, just as you can do with AppleScript, Java-
Script, shell scripts, and scripts in other languages. So if you have a
macro that can mostly be accomplished with prebuilt actions, but
just needs a bit of custom code, you can use Swift to write that code.

• SwiftAutomation is a free framework written by a developer known


as Hengist Podd. It provides a bridge to Apple events for Swift,
meaning that Swift can be used to control any app that would
otherwise be controllable with AppleScript. SwiftAutomation is
clearly a work in progress, and its documentation is only partially
complete, but it may be worth experimenting with.

170
Use Services for
Systemwide Shortcuts
In macOS, a service is a special, context-sensitive program that can
operate almost anywhere. You can find services on the Services sub-
menu of the application menu (that is, the menu with the current app’s
name). Alternatively, right-click (or Control-click) something and
choose a service from the very bottom of the contextual menu. (Ser-
vices appear on a Services submenu of the contextual menu if more
than four of them are active and applicable to whatever you selected.)

Note: Quick Actions are a subset of services that includes any service
you create as described in this chapter. Starting in Monterey, Quick
Actions no longer appear in the Services submenu of the Finder’s
right-click/Control-click contextual menus, but rather in the Quick
Actions submenu. In addition, they still appear in Application Name >
Services.

If you look at the Services or Quick Actions submenus in different


apps, and with different things selected, you’ll notice that your choices
change. For example, you’ll see one set of commands when you select a
file in the Finder, a different set when you select text in Mail, and yet
another set when you have a graphic open in Preview. That’s because
each service is designed to operate only on certain kinds of data, or in
certain contexts. The idea is to show you only the commands that are
relevant to what you’re currently doing.

Services, like Automator workflows and AppleScripts (discussed later


in this book), can perform complex tasks for you with only one click.
So they’re fantastic automation tools that every Mac user should be
aware of. As we’ll see in a moment, you can use a combination of built-
in services, third-party services, and services you create yourself to
automate a wide variety of activities.

171
Before you do anything else, you should configure the services on your
Mac to your taste. Not all the services installed on your Mac are neces-
sarily active (only active services appear on the Services or Quick
Actions submenus); you can enable or disable services as you wish. In
addition, you can assign a keyboard shortcut to any service to avoid
hunting for it in a hard-to-reach submenu.

Configure Services
To set up Services on your Mac:

1. In Ventura or later, go to System Settings > Keyboard > Keyboard


Shortcuts > Services (see Figure 46); in Monterey or earlier, go to
System Preferences > Keyboard > Shortcuts > Services.

Figure 46: Enable, disable, or add keyboard shortcuts to services


here.

2. Select the checkbox next to any service you want to enable; deselect
those you want to disable. (Remember, selected services appear in
the Services or Quick Actions submenu only when the context—the
app and data type—are appropriate.)

172
3. To add a keyboard shortcut to a service that doesn’t have one in
Ventura or later, double-click the light gray word “none” to the right
of the service name; in Monterey or earlier, click “none” once and
click Add Shortcut. (To change an existing shortcut, double-click it.)

4. Press the new key combination you want to use for the service. (To
remove a shortcut, select it and press Delete.)

Ordinarily, changes to the Services menu happen immediately, so you


can try out your newly activated service or shortcut right away.

Find and Use Services


You can explore the many built-in Quick Actions and other services in
macOS by selecting various kinds of things (text, files, images, URLs)
and then either viewing the Application > Services submenu or right-
clicking/Control-clicking to view the Quick Actions submenu. For
example, select a word and choose Look Up in Dictionary from the
Services submenu to open the Dictionary app with that word’s defini-
tion showing, or select a graphic in the Finder and choose Set Desktop
Picture to make it your Desktop picture without having to open System
Preferences > Desktop & Screen Saver > Desktop and adding it there
manually. In addition, some apps install their own services.

Beyond what comes with macOS and the apps you already have, there
are a great many free services you can download that are extremely
useful. For instance:
• The Download Services page at Mac OS X Automation has dozens of
services for images, email, movies, PDFs, web browsing, and other
contexts.
• DEVONtechnologies’ Download page has two services: CalcService
(for performing calculations on text selections) and my favorite,
WordService (which includes numerous commands for reformat-
ting and manipulating text).
• Markdown Service Tools from Brett Terpstra help you format text
using the popular Markdown syntax.

173
Once you’ve downloaded a service, move or copy it into /Library/
Services (to make it available to all users) or ~/Library/Services (to
make it available only to you). Then go back to System Settings >
Keyboard > Keyboard Shortcuts > Services or System Preferences >
Keyboard > Shortcuts > Services to enable the specific commands you
want to use and assign or change keyboard shortcuts.

But wait, there’s more! You can create your very own service, without
any programming at all, using Automator, which I discuss in the next
chapter. (For instructions, see the Create Your Own Service).

Tip: To learn more about services, visit the Services portion of the
Mac OS X Automation site. The page is quite old, but most of the
information is still applicable to recent versions of macOS.

174
Get Started with
Shortcuts
This entire book is about shortcuts in the generic sense: things that
save you time and effort. In this chapter, however, I want to introduce
you to the app called Shortcuts, and the automations you can create
with it—which are, of course, also called shortcuts!

Although Mac users have long had an embarrassment of riches when it


comes to automation options, these opportunities in iOS and iPadOS
were negligible until the release of a third-party app called Workflow.
After watching this app’s popularity over a few years, Apple bought it,
renamed it to Shortcuts, and expanded its capabilities.

Once Shortcuts reached a sufficient level of maturity and usefulness in


iOS and iPadOS, Apple brought it to the Mac, too, starting in Mon-
terey. In Ventura, Apple added a number of features and refinements;
see the sidebar Shortcuts Improvements in Ventura, ahead. For the
time being, Shortcuts supplements the existing options rather than
replacing any of them, though (as I explain shortly) Apple does seem to
be treating it as a successor to Automator.

Like Automator, Shortcuts works by stringing together a sequence of


actions—some provided by Shortcuts itself, and others provided by
various apps. Although the selection of actions and the layout of the
screen are different, the basic process is similar. However, Shortcuts
offers additional logic, such as an If action and built-in calculation
tools, that can make it easier to achieve complex goals without relying
on embedded AppleScripts or shell scripts.

If you’ve used Shortcuts in iOS or iPadOS, you’ll feel right at home in


Shortcuts for Mac. In fact, it automatically syncs and displays all your
existing shortcuts, many of which will continue to work without modi-
fication. (Shortcuts made on iOS/iPadOS are compatible only with M-
series Macs or, on Intel-based Macs, apps built with Mac Catalyst.) For

175
those new to Shortcuts, you’re in for a treat: it provides a friendly,
approachable way to string together a wide variety of tasks that then
run on demand or when certain conditions are met.

Note: In this chapter I offer just a very brief introduction to Short-


cuts. To learn about the app in detail, read Take Control of Shortcuts
by Rosemary Orchard.

Shortcuts Improvements in Ventura


The Shortcuts app in Ventura and Sonoma looks and acts almost the
same as the version in Monterey. However, there were a few note-
worthy improvements in Ventura:
✦ New actions for Books, Clock, Reminders, and Safari, and updates
to existing actions for Calendar and Clock
✦ A new Get Current Focus action, as well as Focus Filter actions for
certain apps
✦ A Search in Shortcuts action
✦ Updates to the Get Battery State, Get Current Weather, and Send
Email actions
✦ A new Show in Share Sheet option (previously available only in
iOS/iPadOS)
✦ App Shortcuts—prebuilt, single-action shortcuts bundled with
certain App Store apps
✦ Changes to the process for sharing shortcuts (see Share a Short-
cut, later)
✦ Various other small user interface changes

Explore Shortcuts
Let’s take a moment to look around the Shortcuts app and explore
some of the prebuilt shortcuts you can use without any extra effort.
This point is pretty important: you can get a lot of value from Shortcuts
without ever creating any of your own custom shortcuts. You can also
customize these existing shortcuts to meet your needs.

176
When you open Shortcuts (found in /Applications), you should see
something like Figure 47. You will, of course, have different shortcuts
than I do, and what you see will depend on which category is selected
in the sidebar. Figure 47 shows All Shortcuts selected, which includes
any shortcuts you had on your iOS/iPadOS devices, as well as a Starter
Shortcuts category with some examples from Apple. (You can also see
those by selecting Starter Shortcuts in the sidebar.) We’ll get back to
the Starter Shortcuts in a moment.

Figure 47: The All Shortcuts view in the Shortcuts app as it hap-
pened to appear on one of my Macs.

To see a wide collection of shortcuts supplied by Apple, select Gallery


(Figure 48). Each of these can be installed with one click.

177
Figure 48: Gallery shows shortcuts from Apple you can install.

Browse through the Gallery, using the “See All” links in each category,
to find more shortcuts, or use the Search field to look for something of
interest. When you find a shortcut you’d like to try, click its plus
icon to install it. It then appears in All Shortcuts.

Run a Shortcut
Once you’ve found and installed a shortcut you want to use (or created
one yourself, as I discuss shortly), there are many ways to run it. Here
are a few of them:

• Click play: Hover over the tile for any installed shortcut and click
its play icon.

• Use Siri: Activate Siri and say the shortcut name. For example, if
you have Listen for “Hey Siri” selected in System Preferences > Siri,
you could say “Hey Siri, Text Last Image” to run the Text Last
Image shortcut.

178
• Use the Dock: Click and hold, right-click, or Control-click the
Shortcuts Dock icon and choose Run Shortcut > Shortcut Name
from the contextual menu.

• Use Spotlight: Activate Spotlight (with ⌘-Space or using the


Spotlight icon on your menu bar), search for the shortcut by
name, and double-click it.

• Use the menu bar: Drag any installed shortcut to the Menu Bar
category in the sidebar. Once you’ve done that, you can choose the
shortcut’s name from the Shortcuts icon that appears on your
menu bar. If you hover over the shortcut name, you can click the
arrow icon on the right side to open the shortcut for editing.

• Use the Services/Quick Actions menu: Drag any installed


shortcut to the Quick Actions category in the sidebar. Thereafter,
the shortcut appears in:

‣ The Services submenu of the application menu (that is, Applica-


tion name > Services)

‣ The Quick Actions or Services submenu, depending on your


version of macOS, of the contextual menu that appears when you
right-click or Control-click pretty much anything in the Finder or
another app

• Use the command line: In the Terminal app, you can enter
shortcuts run name (where name is replaced with the shortcut’s
name) to run that shortcut; you can also enter shortcuts list to see
what shortcuts are available. Jason Snell offers even more details
and tricks in his article Run shortcuts from the Mac command line.

Tip: You can also run a shortcut by clicking a button on an Elgato


Stream Deck. See Control Anything with a Stream Deck for details.

Import Automator Workflows


To hear Apple tell the story, it sounds like Shortcuts can import pretty

179
much any existing Automator workflow you might have, converting it
to a shortcut with the same functionality. In my experiments so far,
almost every attempt to import Automator workflows failed in one way
or another. Often, an error message would appear, informing me that
some action within the workflow was incompatible with Shortcuts
(Figure 49). On other occasions, Shortcuts imported the workflow
successfully, but then failed to run it without throwing an error.

Figure 49: An alert like this appears when Shortcuts is unable to


import an Automator workflow due to an incompatible action.

Perhaps the most common reason Shortcuts fails to import an Aut-


omator workflow is that the workflow includes actions from other apps
that don’t offer the same actions for Shortcuts. For example, many of
my Automator workflows involve actions from apps such as BBEdit
(which currently offers only two basic Shortcuts actions) and Preview
(which offers no Shortcuts actions). Without those third-party connec-
tions, recreating those capabilities in Shortcuts is a nonstarter, let
alone importing the Automator workflows. We can only hope that
support by other apps improves in the future.

So, with the gigantic qualification that the process is as likely as not to
fail, here’s how to import a workflow:

1. In Shortcuts, choose File > Import.

180
2. Navigate to the Automator workflow you want to import and select it.

3. Click Open.

That’s it! If you’re lucky, Shortcuts creates a new shortcut that works
just like the old workflow.

Customize a Shortcut
A great way to understand how shortcuts work is to open a bunch of
the sample shortcuts Apple supplies and examine how the actions are
arranged and configured. Then, try a few small changes here and there
to see what happens. By making simple changes (such as changing the
contents of a text field or which app is used to open a given file type),
you can then customize shortcuts to better meet your needs. Having
done that, you can experiment with adding, removing, or swapping out
actions until you become comfortable enough to create your own
shortcuts from scratch.

In any case, you alter a shortcut’s contents in the Shortcuts editor,


which appears when you double-click an existing shortcut or choose
File > New Shortcut to create your own (Figure 50).

Available actions appear in the sidebar on the right. You can sort them
by category or app, or use the Search field to look for an action that fits
the bill. To add an action to your shortcut, either double-click it or drag
it into the editing view. You can then rearrange actions using drag and
drop, fill in additional parameters (which sometimes requires clicking
Show More), or delete an action by hovering over it and clicking its
close icon.

As you add actions, the Suggestions category displays actions that


seem potentially useful as next steps, to make them easier to find.

181
Figure 50: The Shortcuts editor, showing one of Apple’s starter
shortcuts.

Note: Like Automator, Shortcuts supports AppleScript, JavaScript,


and shell scripts; adding code using one of these scripting languages
can extend your shortcut’s capabilities far beyond what the built-in
actions offer. However, support for scripting languages is disabled by
default. To enable it, choose Shortcuts > Settings/Preferences >
Advanced, and select Allow Running Scripts.

Because some actions have to communicate with other apps or web


services, Apple requires your permission for them to run. This is
because they could potentially send private information or require
login credentials. If you add an action that requires permission, you’ll
see a notice such those shown in Figure 51. To grant permission, click
Allow Access and follow any additional prompts that appear.

182
Figure 51: Actions that might have privacy implications ask you to
grant them access.

Create a Shortcut
Just to give you a quick Shortcuts example to get your feet wet, let’s
create a new shortcut from scratch that sends a message to the recipi-
ent of your choice with the title and artist of whatever song you’re
currently listening to in Music. That in itself may not be particularly
useful, but it provides a good way to illustrate some of the basic behav-
iors of Shortcuts.

Follow these steps:

1. Open Shortcuts if it’s not already running and click the Add Short-
cut icon on the toolbar.

2. Click in the Shortcut Name field at the very top of the new window
that opens and type a name for your shortcut, such as Send Message
with Current Song and Artist.

3. Add your first action. Since we want to know what’s currently


playing in Music, we’ll use the Get Current Song action. You can
find that in the sidebar on the right side of the window in the Media
category (if Categories is selected) or after selecting Music (if Apps
is selected); or you can type get current song into the Search field.
Once you’ve found that action, double-click it to add it to the top of
your shortcut.

183
The Get Current Song action hands Shortcuts all the information
about the current song, including the album name, song duration,
and tons of other metadata. We want two specific pieces of informa-
tion—the song title and the artist name—so we’ll add actions to get
those items and put them into variables to use later.

4. Find the Set Variable action. Find it in the Scripting category with
Categories selected, or search for set variable. Double-click it to
add it to your shortcut. So far, your shortcut looks like Figure 52.

Figure 52: A new variable linked to the first action.

5. Click in the Variable Name field and type a name for the variable—
we’ll use SongTitle.

6. The variable is currently getting its input from the item above it, as
indicated by the vertical line that connects the two. But the value of
the variable is set by default to Current Song, which is not what we
want. We want something more specific—the song title. To get that,
click Current Song, and, in the popover that appears, scroll down in
the Get list at the bottom to Title and select it. The variable value
changes to Title (Figure 53).

184
Figure 53: Select the value of the SongTitle variable here.

7. Next we want to create a second variable to hold the artist’s name.


So repeat step 4 to add another Set Variable action below the first
one, and name it ArtistName as in step 5.

8. In an effort to be helpful, Shortcuts prefills the variable name of the


previous action (SongTitle) as its value, but that’s not what we want.
Begin by clicking SongTitle on the right side of the ArtistName
variable and then click Clear to remove the link to the previous
action.

9. Next, click the Input label that now appears next to ArtistName and
choose Select Variable (Ventura or later) or Select Magic Variable
(Monterey) from the contextual menu.

Note: In the next few steps, you might think, “Wait, this is weird.
Why am I doing this?” And if you use Monterey, you may be thinking,
“Magic Variable…huh?” I sympathize. Shortcuts is kind of weird in
spots. To learn all about magic variables and break through much
(though not all) of the weirdness, read Take Control of Shortcuts.

185
10. Select the Current Song item that appears underneath the Get
Current Song action and (in Monterey only) click Done.

11. Click Current Song in the ArtistName variable and select Artist
from the Get list at the bottom. Your shortcut should now look like
Figure 54.

Figure 54: The shortcut as it appears after adding the first three
actions.

12. Now that we have two variables with the information we’re looking
for, we can use them to send a message. Add a Send Message
action to your shortcut, which you can find in the Sharing catego-
ry, under the Messages app, or using search.

13. We want to edit the contents of the message, which are set to
ArtistName by default. Doing this is a bit tricky: double-click just
to the right of the ArtistName variable in the Send Message action.
(It may take a few tries to find the exact spot.) The variable name
darkens and an insertion point appears. Press ← to move the
insertion point to the left of the variable and type I’m currently
listening to (followed by a space). Then type SongTitle, which
pops up the variable by the same name; click that. Type a space,
the word by, and another space. Press → and type a period.

14. Click Recipients. Select a recipient from your Contacts list (I


recommend selecting yourself for testing purposes). Your shortcut
should now look approximately like Figure 55.

186
Figure 55: The finished (for now) example shortcut.

To test your shortcut, open the Music app and play something. Then
return to Shortcuts and click the play icon on the toolbar. You
should see something like Figure 56; at this point you can go ahead
and click Send to send the message or click Cancel.

Figure 56: The result of running the above shortcut.

But wait a minute. What if Music isn’t open or no song is selected? The
shortcut would work, but because the variables are empty, it would just
say “I’m currently listening to by.” We could avoid this by adding an If
statement to first check and see if the current song has any value. If it
doesn’t, we could display an error message and stop; if it does, we can
run the rest of the shortcut.

187
To add the new logic, follow these steps:

1. Add the If action (found in the Scripting category) and drag it to just
below the Get Current Song action.

2. In the If action, click Condition (to the right of Current Song, which
should be filled in automatically) and choose “does not have any
value” from the pop-up menu.

To this point, we’ve created an If statement that says: “If the current
song has no value, do something; otherwise, do something else.” So
now let’s fill in the “something” and “something else.”

3. Find the Show Alert action and drag it into your shortcut right after
the first portion of the If action. (You might have to drag it well
below where you want it to go for the above and below actions to
slide out of the way to accommodate it.)

4. Select “Do you want to continue?” and replace it with your own text,
such as Music isn’t playing anything right now.

5. Drag each of the three remaining original actions of your shortcut


one by one between the Otherwise portion of the If action and the
End If portion. Your shortcut should now look like Figure 57.

188
Figure 57: An If statement can add branching logic to your shortcut.

If you now quit Music and run the shortcut, you should get the alert
from step 4. Open Music and click Play, then run the shortcut again,
and it should work as before.

Could you do more with this shortcut, such as open Music if it’s not
already open, send a message without a prompt, or play a particular
track or playlist? Absolutely—all that and more. I leave those details as
homework for you.

Share a Shortcut
Your shortcuts automatically sync across your own devices—that is,
those signed in with the same Apple ID.

Note: iCloud Sync is on by default. You can change that by going to


Shortcuts > Settings/Preferences.

189
However, if you want to share a shortcut with someone else, you can
use the Share menu, just as in any other app. Depending on the
actions in the shortcut you share, the recipient may be prompted to
approve sending data to other locations—anything that might poten-
tially affect their privacy should require explicit permission.

Note: Normally, shortcuts you share go through Apple, and Apple


may review them (for security purposes and other reasons). If the
recipient has selected Shortcuts > Settings/Preferences > General >
Private Sharing (and you’re in their Contacts), that review won’t
happen, but that also leaves open the possibility of running a mali-
cious or dangerous shortcut.

190
Get Started with
Automator
Automator is an easy-to-use technology, included as part of macOS, for
bundling actions into sequences known as workflows. If programming
gives you the willies, Automator is nothing to fear. You don’t have to
learn a new language or write in code—just drag things into a list, fill in
some blanks, and check some boxes.

Note: Although it’s often lumped together with AppleScript (which I


discuss in the next chapter), Automator is a completely independent
technology that just happens to be capable of many of the same
things.

For example, a workflow can:

• Convert text files and graphics into an ebook in EPUB format

• Create a graphic from a word or phrase

• Import all the images from a webpage into Photos

• Create and mount a new disk image

• Convert a movie file to a size and format suitable for your iPhone or
iPad

• Create an audio file with a synthesized voice reading the contents of


a text file

• Add a 1-pixel border around any graphic

• Upload a file to each of several server destinations—with a different,


pattern-based name in each place (that’s how we upload Take
Control books to the various places they need to go when they’re
ready for sale!)

191
In much the same way as in Shortcuts, workflows are made from
building blocks called actions. Automator includes many actions, as do
a number of the applications bundled with macOS (such as Calendar,
Contacts, Mail, Music, and Preview). Just as a third-party app may or
may not include AppleScript support, some apps come with their own
Automator actions and some don’t. A few third-party apps with good
Automator support are BBEdit, LaunchBar, Microsoft Office, Pixelma-
tor, and Transmit. (In some cases, notably BBEdit, Automator support
for an app requires a separate download and installation.) In addition,
actions can optionally contain instructions written in numerous
programming and scripting languages, including AppleScript; Java-
Script; Perl, Python, and Ruby (if installed); and shell scripts.

I’ll show you how to make a few simple Automator workflows. Then I’ll
tell you about some of your other options, where to find existing
workflows that you can use as is or modify to meet your needs, and
how to learn more about Automator.

Tip: If you’re unsure whether Automator or AppleScript is the best


tool for a certain automation task, my advice is to try Automator first,
because it’s so much easier to use. If you get stuck, you can fall back
on AppleScript (possibly even including the necessary AppleScript
code as part of your Automator workflow).

Create a Simple Automator Workflow


For an easy (yet somewhat fancy) introduction, we’ll create a workflow
that asks you to type some text, and then speaks it back to you:

1. Open Automator (in /Applications).

2. Click New Document.

3. In the dialog that appears, select Workflow (the default) as the


document type and click Choose. Your window should now look
something like Figure 58.

192
Figure 58: An empty Automator workflow window.

4. If you don’t see a Library list in a sidebar on the left, click Show
Library on the toolbar.

The Library is the list of available actions. You can click a category
or app name to see its available actions, or type a search term into
the Search field to find matching actions.

5. Type text into the Search field to show only text-related actions in
the second column.

6. Locate the Ask for Text action in the second column, and drag it
into the workflow area on the right (Figure 59).

As the name suggests, this action displays a dialog that asks you to
enter text.

193
Figure 59: The Ask for Text action, ready to be filled in.

7. Fill in the question you want the dialog to ask, such as What would
you like me to say? and, if you like, fill in a default answer, such as
Beep. Select the Require an Answer checkbox to ensure that some
text must be entered (so that the workflow always does something).

8. Return to the second column, find the Speak Text action, and drag it
below the Ask for Text action (Figure 60).

You’ll notice that the two actions join together to show that the
output of the first one (whatever you type into the dialog) is fed as
input into the second one.

Figure 60: Two actions joined into a workflow.

9. If you like, choose a different voice from the Voice pop-up menu.

194
Your workflow is now ready. To run it, click the Run button on the
toolbar. You should see a dialog asking you what you want it to say.
Accept the default answer or supply a new one, click OK, and your Mac
speaks that text.

That’s the general idea of workflows. Usually, one action produces


some sort of output (a file, a URL, text, or whatever) and feeds that to
the next action, which does something with it and passes it along to
another action—and so on. The final action provides the result in the
form you’re looking for (a modified file, information in a dialog, an
open webpage, or what-have-you).

To reuse a workflow, save it (choose File > Save, choose a name and
location, and click Save); you can then double-click it to reopen it in
Automator. Or you can save it as an app (same procedure, but choose
Application from the File Format menu in the Save dialog), and you get
a standalone, double-clickable Automator app. (For other ways to
package a workflow, see the sidebar Automator Workflow Types.)

Create an Automator Droplet


I mentioned a moment ago that you can save an Automator action as a
double-clickable app. Automator apps can also function as droplets—
that is, they’ll perform the actions you specify on any files or folders
you drag and drop onto the app icon. I’d like to show you a quick
example, and in the process point out a few other interesting things
about Automator. For this example, we’ll create a droplet that scales
images to 50% of their original size, saves them as JPEGs (regardless
of their original format), and renames them, changing the case to Title
Case and adding the word “Scaled” to the filename.

Follow these steps:

1. Open Automator. If the new document window doesn’t appear


automatically, choose File > New.

2. Click Application, followed by Choose.

195
3. From the Photos category, drag the Scale Images action to your
workflow.

An alert appears, telling you that the action you just added will
change files passed into it. If you wanted Automator to add a step
here so that it works on a copy of the file instead, you could click
Add. But for the purpose of this example, we don’t—we’re going to
go ahead and change the original—so click Don’t Add. (You’ll see
this alert a few more times before we’re done with this workflow!)

4. In the Scale Images action, choose By Percentage from the pop-up


menu and fill in 50 in the field that follows.

5. From the Photos category, drag the Change Type of Images action
to your workflow. Once again, click Don’t Add in the alert that
appears. Choose JPEG from the To Type pop-up menu.

6. From the Files & Folders category, drag the Rename Finder Items
action to your workflow. Click Don’t Add, as usual. From the first
pop-up menu, choose Change Case. Leave the second set to “Base-
name only,” and choose Title Case from the third.

7. From the Files & Folders category, drag another instance of Re-
name Finder Items to your workflow, and yet again, click Don’t
Add. This time, choose Add Text from the first pop-up menu. Then
fill in “ Scaled” (that is, a space followed by the word Scaled) in the
text field, and leave the other pop-up menu set to “after name.”

8. Choose File > Save, enter a name (such as Scale & Rename), and
save the app. The final version should look something like Figure
61.

196
Figure 61: The final version of the Scale & Rename app.

To run the app, first make a copy of a graphic that you don’t mind
altering, or take a quick screenshot just so you have a disposable
graphic file to work with. Drag that graphic onto the app you saved in
step 8. You should see the title change (for example, “my graphic.png”
would become “My Graphic Scaled.jpg”) and if you open the graphic in
Preview, you’ll see that it’s in JPEG format and at 50% of its original
size. (Needless to say, you can adjust the size, format, and naming to
something that would be more useful to you.)

I want to point out a few things about this workflow:

• You can reorder the steps any which way. In some cases, order is
significant (you need to make one change before making another
one that depends on it), but in this case, it doesn’t matter. You
could, for example, drag the two renaming steps above the two
image steps and get exactly the same result.

197
• Although I asked you to opt out of the steps that make copies of the
file (just to keep the example short and sweet), you should pay
attention to that option in real life—especially when a file format
changes or unrecoverable data might be lost.

• Sometimes you need multiple instances of the same action (as with
“Rename Finder Items” here) to get the desired end result.

Create Your Own Service


Services help you automate common tasks—but what about uncom-
mon tasks: things you’d like a service to do, but for which you can’t
find a prebuilt solution? Even if you’re not a programmer, you can
create your own service—more precisely, a type of service called a
Quick Action—with Automator!

Tip: Forgotten what services are? Refer back to Use Services for
Systemwide Shortcuts.

To create a service, open Automator and create a new workflow (see


Create a Simple Automator Workflow), but instead of selecting Work-
flow as the document type, select Quick Action. When you do so, a few
new options appear at the top of your workflow; fill them in to specify
how and where your service will work:

• Workflow receives current: From this pop-up menu, choose


the type of data that must be selected for the service to appear; the
service then receives the selected data as input. For example, choose
“text,” “dates,” “files or folders,” “image files,” or “web content.” (To
create a service that requires no input at all, choose “no input.”)

• in: Use this pop-up menu to choose whether your service should be
available in any application, or only in a specific application.
(Choose Other and navigate to the app if it doesn’t appear in the
menu.)

• Input is: For certain data types only, you can use this pop-up
menu to determine whether the service acts on the Entire Selection

198
or only the relevant portion of it—for example, Only Addresses,
Only URLs, or Only Dates.

• Output replaces selected text: For text and rich text selections
only, check this box if you want the service to replace whatever’s
selected after the service runs. For example, if you select a word and
run a service that translates it into another language, you may want
the translated word to replace the original.

Then build your workflow as usual, save it, and give it a name. Aut-
omator automatically stores it in ~/Library/Services.

Here’s a simple example that scans selected text, extracts all email
addresses that end in icloud.com, puts those in a new text file, one
address per line, and displays that document.

Note: At this point in previous editions of this book, I described a


sample service using the Create Banner Image from Text action to
create an image from selected text. Unfortunately, in Sonoma, that
action produces an error when run as part of a service, so I’ve pro-
vided a different example in this edition.

To create this service:

1. Open Automator. If the new document window doesn’t appear


automatically, choose File > New.

2. Click Quick Action, followed by Choose. Leave the settings in the


top portion of the window set at their defaults.

3. From the Text category, drag the action Extract Data from Text to
the workflow. From the Extract pop-up menu, choose “email ad-
dresses.” (You could instead just as easily choose a different catego-
ry to extract URLs, dates, addresses, or phone numbers.)

4. From the Text category, drag the Filter Paragraphs action to the
workflow. From the “Return paragraphs that” pop-up menu, choose
“contain,” and in the field that follows it, type icloud.com.

5. Returning to the Text category once more, drag the New TextEdit
Document action to the workflow.

199
Your workflow should now look something like Figure 62.

Figure 62: This service workflow converts selected text to an image.

6. Now choose File > Save and give your workflow a name (such as
Extract iCloud Addresses).

To use the workflow, find or create text containing at least one email
address ending in icloud.com. (For testing, you could grab some dummy
text from www.lipsum.com, paste it into any word processor, and type
in a few icloud.com addresses here and there.) Select the text and then
choose Application Name > Services > Service Name, where “Applica-
tion Name” is the name of the app you’re using and “Service Name” is
the name you chose in step 5. Automator scans the text, extracts the
email addresses, filters them so that only the icloud.com addresses
appear, adds those (one per line) to a text file, and opens it in TextEdit.

Note: Starting in Monterey, Quick Actions no longer appear in the


Services submenu of the Finder’s right-click/Control-click contextual
menus, but rather in the Quick Actions submenu. But they also still
do appear in Application Name > Services.

200
Tip: If you ever encounter a situation in which you explicitly want to
avoid having an action take input from the previous step in an Aut-
omator workflow, right-click (or Control-click) it and choose Ignore
Input from the contextual menu. (That command is disabled in
contexts where it would lead to an unusable workflow.)

Automator Workflow Types


When you create a new workflow, a dialog asks you to choose a
document type. Here’s what the options mean:
✦ Workflow: A workflow that runs only in the Automator app.
✦ Application: A standalone, double-clickable app (which can also
function as a droplet that operates on items you drop onto it).
✦ Quick Action: A program that’s available anywhere on your Mac
but that operates only on certain kinds of data. (See Use Services
for Systemwide Shortcuts, the previous chapter, and Create Your
Own Service, earlier in this chapter.)
✦ Print Plugin: Also known as a PDF workflow, this is a command
that appears in the pop-up menu at the bottom of Print dialogs—
that is, instead of sending a file directly to your printer, you can
send it to an Automator workflow as a PDF.
✦ Folder Action: A workflow that operates on the contents of a
specific folder when those contents change. This is similar to an
AppleScript folder action (see Use AppleScript Folder Actions).
✦ Calendar Alarm: When you set an alarm in Calendar, your
choices are normally Message with Sound, Email, and Open File
(see Use Calendar Events). This workflow type gives you another
option: trigger a workflow at the alarm time.
✦ Image Capture Plugin: The Image Capture app accepts input
from scanners and digital cameras. With a workflow of this type,
Automator can process whatever comes in via Image Capture.
✦ Dictation Command: A workflow you activate with a spoken
command; see Control Your Mac with Your Voice.
If you choose the wrong type when you created a workflow, you can
change it; choose File > Convert To, select a different type, and click
Choose. Make any needed adjustments and save the new workflow.

201
Enabling Third-Party Actions in Automator
The first time you attempt to run a workflow that contains an action
provided by a third-party (non–Apple) app, at least in Ventura or
later, Apple prompts you to enable such actions (Figure 63).

Figure 63: This alert tells you to explicitly enable third-party actions.
Click Open Automator. Then choose Automator > Third Party Aut-
omator Actions. In the dialog that appears (Figure 64), select
“Enable Automator actions from third parties” and click OK.

Figure 64: Check the box here and click OK.


You can now use any third-party action in your workflows.

202
Find and Run Sample Workflows
Automator workflows you find online usually work unmodified on your
Mac—you double-click them and, depending on how they were saved,
you either run them in Automator or they run as apps. (If you want to
edit an Automator app, drop it onto the Automator icon.)

Try some of the sample workflows (most of which should still work
fine, even if they’re a bit old) at these sites:

• 15 Automator and AppleScripts You Can’t Live Without at Tech-


Radar

• 10 Awesome Uses for Automator Explained at Tuts+

Tip: If a workflow doesn’t function on your Mac, it may have been


configured to look for a file or folder in a specific location that doesn’t
exist on your Mac. You should be able to change the relevant
action(s) to point to valid locations. Another possibility is that the
author used an Automator action or app you don’t have installed. An
error message should tell you its name; you can then do a web
search to locate it, install it, and try the workflow again.

You may find workflows that almost do what you want them to do.
Feel free to experiment by changing options within actions, or swap-
ping out one action for another. Unlike AppleScript, Automator makes
it simple to tinker without worrying that you’ll make a syntax error or
have no idea what command to use—your only building blocks are the
actions you see in the list.

Learn More about Automator


If you want to learn much more about working with Automator:

• See the Automator portion of the Mac OS X Automation site.

• Read Neil North’s Automator for Mac OS X: Tutorial and Examples.

203
Get Started with
AppleScript
Whereas Automator lets you construct a workflow visually by dragging
and dropping actions into a list, AppleScript is a scripting language—a
type of simplified programming language that runs only in a specific
environment (in this case, macOS). That means AppleScripts can run
only on a Mac, and because your Mac must interpret the commands in
the script as it runs, an AppleScript won’t have the high performance
of a conventional Mac app. Even so, AppleScripts can look and act like
ordinary Mac apps. You may already be using some apps that were
written in AppleScript without even realizing it!

AppleScript has been around since way back in 1993, and it’s become
popular among people who like to tinker but wouldn’t consider
themselves programmers, because it’s built into macOS and is a lot
easier to work with than a big, complicated language like Swift or
Objective-C. AppleScript is often referred to as “English-like,” which is
a generous description at best, but if you don’t know much about
programming, you can probably make more sense of AppleScript code
than, say, Java.

Write a Simple AppleScript


In a moment, I’ll give you some examples of what you can do with
AppleScript (see Learn What AppleScript Can Do). But first—before I
lose the attention of people who think programming is Just Too
Scary—I’m going to show you how to write a complete AppleScript
program with exactly one English word. Here we go:

1. Open Script Editor in /Applications/Utilities.

2. In the window that appears, click New Document. A blank window


opens.

204
3. Type the word beep (Figure 65). Your script is now complete!

Figure 65: Here’s your first complete AppleScript!

4. Click the Run button.

Two things should happen:


• First, you’ll hear your system alert sound. That was your program
running—congratulations!
• Second, you’ll notice that the word beep changed its appearance
from a purple, monospaced font to a bold, blue, proportional font.
That’s because when you try to run an AppleScript, the script editor
first compiles it, a process that checks to make sure it’s properly
written. If it is, it formats the entire script in an easier-to-read
fashion (which will be more apparent with a longer script).

Tip: You can manually compile a script (without running it) to check
its syntax, reformat it, and add automatic indentation by choosing
Script > Compile (⌘-K) or clicking the Compile button on the
toolbar.

Now that you’ve written and run an AppleScript, you can follow the
same steps to run scripts other people have written—simply type (or
copy and paste) the scripts into AppleScript Editor and click the Run

205
button. We’ll come back to this idea in a bit, but for now, I merely
want to point out that using AppleScript can be as simple as that.

Learn What AppleScript Can Do


The simplest way to think about what AppleScript can do is that it
provides an alternative means of performing common actions in
macOS and in many apps. For example, you can open or quit an app
with a menu command or the keyboard; AppleScript can also open or
quit an app as part of a script. You can rename a file in the Finder; an
AppleScript can do that too. You can open a word processor, search for
a certain word, highlight the entire paragraph it appears in, make it
bold, copy it, switch to another app, and paste it—or let AppleScript do
all that for you with one click.
It’s that last type of activity—combining strings of actions that involve
multiple apps—where AppleScript especially shines. AppleScript is also
good at repetitive tasks (say, renaming files spread across different
folders or fetching a long list of items from one place and copying them
to another place) that would otherwise be tedious. And it gives you
access to features on your Mac that aren’t normally exposed. For
example, you just wrote a script that plays a beep, and although that
happens when there’s an error, there’s no button or menu command
that lets you manually trigger a beep. (AppleScript can trigger lots of
actions that are far more interesting and useful than a beep!)
More importantly, an AppleScript can include logic that enables it to
make decisions as it runs—either on its own, or with your input. It can
use programming constructs such as variables, if-then conditions, and
loops, and it can tie into numerous other automation tools (such as
TextExpander, LaunchBar, and Keyboard Maestro).

Fine, you may say, but what exactly can AppleScript do?

Well, if you want to know every built-in command and option, with
detailed background and examples, check out Apple’s massive
Introduction to AppleScript Language Guide. It’s written mainly for
developers, but it’s reasonably clear, and well worth consulting.

206
But that tells you only about AppleScript. To find out what you can do
with AppleScript in a particular app, you’ll need to look elsewhere.

Every app that supports AppleScript, including the Finder, contains a


dictionary of all the nouns and verbs AppleScript can use to control it.
For example, the Calendar app’s dictionary contains verbs like create
calendar and switch view; and nouns like calendar, sound alarm,
attendee, and event. To see what’s in any app’s dictionary, you can
either choose File > Open Dictionary in Script Editor, select an app,
and click Choose, or drag an individual app’s icon from the Applica-
tions folder onto the Script Editor icon. Either way, you’ll see some-
thing like Figure 66. Look through the terms and read some of the
definitions to see what sorts of things AppleScript can do in that app.

Figure 66: A portion of the AppleScript dictionary for Calendar.

Unfortunately, not all apps support AppleScript, and of those that do,
some of them have rather meager dictionaries (meaning you can’t do
very much with them). But there are enough deeply scriptable apps out
there to enable you to accomplish a great deal with AppleScript.

I could fill many pages with examples of tasks an AppleScript could


perform, but here are just a few:

• Find and remove duplicate messages in Mail, events in Calendar, or


records in Contacts

• Combine multiple PDFs into a single file

207
• Apply proper title case to the names of all your tracks in Music

• Rotate, resize, or change the format of images

• Download all the MP3 files linked from a webpage

• Rename all the files in a folder with a different extension

• Count the number of email messages in a certain mailbox

I’ll give even more examples as the chapter goes on.

Understand AppleScript Basics


As you’ve seen, a line of AppleScript code can be as simple as a single
word. But they’re usually a bit more elaborate than that. Although even
teaching the rudiments of the AppleScript language would require
many pages, I wanted to give you at least a few pieces of background
information to start your explorations in the right direction and help
you understand the examples ahead. (If you’re impatient, you can
jump right to Find and Run Example AppleScripts, and then check
back here later for some of the details.) Later on, in Learn More About
AppleScript, I’ll tell you where you can get top-to-bottom instruction in
scripting with AppleScript.

Tell Blocks
As you’ll notice in the examples ahead, most scripts start with tell
application "App Name" on a line by itself, and conclude with an end
tell line, with everything else indented in between. These are
examples of tell blocks, a ubiquitous construction in AppleScript. With
a handful of exceptions (that is, commands interpreted by AppleScript
itself rather than sent to an app), nearly everything you do in
AppleScript involves telling some object (an app, a window, a
paragraph) to do something. So you must always pay attention to
which object you’re directing the current command, or set of
commands to.

208
Tell blocks can be nested explicitly, in order to refer to an object that’s
contained inside another object:

tell application "MyApp"


tell front window
do something
end tell
end tell

Or they can be combined like so:

tell front window of application "MyApp" to do something

Either way, if something isn’t working the way you expect, the first
thing you should ask yourself is whether you’re telling the right entity
to do something.

The Line Continuation Character


In AppleScript, each command normally goes on its own line. Instead
of using a semicolon (;) to indicate the end of a command, as some
programming languages use, AppleScript looks for a return character.

Sometimes you’ll have a long AppleScript command that can’t fit on a


single line. That’s no problem; word wrap works in Script Editor just as
in any word processor. However, until you compile or run a script with
a long line, you might find this automatically wrapped code hard to
read. And, on websites and in books like this one, it can sometimes be
hard to tell when you’re looking at a single AppleScript command that
happens to span multiple lines, and when you’re looking at separate
lines.

To address these problems, Script Editor lets you press Option-Return


to insert a line continuation character (¬), which is the script equiva-
lent of a soft return. It means the line breaks at that point and the
remainder of that command is indented underneath when the script is
compiled or run, but the ¬ character itself is ignored (along with any
leading or trailing spaces or tabs), and AppleScript treats the entire
command as being on one line.

209
So this, for example, would be treated as one long line:

display dialog "Wow, I have so much to say that I barely know ¬


where to begin. Let’s start, I suppose, with my childhood…"

Tip: Although the continuation ¬ character is added automatically


when you press Option-Return in Script Editor, if you want to type
that character manually for any reason, press Option-l.

Variables
Like all programming and scripting languages, AppleScript supports
variables of several kinds. In most cases, you don’t need to go through
an extra step of declaring a variable to tell AppleScript what type of
data it will store, because as long as you assign a value to a variable the
first time you use it, AppleScript figures out what its type is automati-
cally. To set a variable, you use the set command, like so:

set someWord to "peaches"

That makes a variable of type string, since what you set it to was a
string. You can also make an integer (set someNum to 12 + 34), a
boolean (set isIt to true), a list (set theItems to {"cube", "sphere",
"wedge"}), and numerous other classes.

How do you later retrieve the value of a variable? Simple: you use the
get command, as in:

get someWord

If you happen to be running your script in Script Editor and it ends


with a get command, the Results area at the bottom of the window
shows the variable’s current value. You an also display the value of a
variable to the user (see Display Dialog, next), pass it to another part of
your script, alter it, and so on.

Display Dialog
Sometimes you’ll want to inform yourself, or whoever’s running your
script, about its results, ask a question, or simply display the current

210
value of a variable for the purpose of debugging or troubleshooting.
For all these purposes and more, you’ll want to become good friends
with the display dialog command, which produces a simple dialog
with customizable buttons (Cancel and OK by default), the text of your
choice, and an optional text entry field.

Here are some common variants—try mixing and matching these to get
different results:

• Dialog with a message only (Figure 67):


display dialog "Hi there"

Figure 67: Dialogs can display hard-coded strings.

• Dialog with a message containing a variable (Figure 68):


set firstName to "Joe"
display dialog "Hi there, " & firstName

Figure 68: Dialogs can display the values of variables.

Note: To combine strings, use an ampersand (&).

• Dialog with a field, whose value goes into a variable (Figure 69):
set firstName to text returned of ¬
(display dialog "What is your name?" default answer "")

211
Figure 69: Dialogs can ask for text responses.

• Dialog with custom buttons (Figure 70):


display dialog "What rhymes with lunch?" ¬
buttons {"Bunch", "Snack", "Table"} default button 1

Figure 70: Dialogs can have custom buttons.

If/Then Statements
You can use an if/then statement (or if/then/else) to execute one or
more commands only if a certain condition is true. Although there are
multiple ways to format these, the most common ones look like these:

set myNum to 3
if myNum is less than 4 then
display dialog "Yes, " & myNum & " is less than 4."
end if

(Note that you must include the word then at the end of the if line; if
you don’t, AppleScript will add it for you.)

212
set firstName to text returned of (display dialog ¬
"What is your name?" default answer "")
if firstName is "Joe" then
display dialog firstName & " is awesome!"
else
display dialog firstName & " is OK."
end if

Comments
To put a note to yourself or other people within a script that won’t be
executed, put two hyphens (--) in front of it, like so:

-- This is Joe’s excellent script. The next line sets a variable.


set myVar to "something"
-- Next we display that variable in a dialog.
display dialog myVar

If your comment runs longer than a line, you can instead surround it
with (* and *), like this:

(* Wow, there’s so much to say about this excellent script. Where


can I even begin? Well, let’s start at the beginning. Once upon a
time… *)

And That’s Just the Barest Beginning…


There’s so much more to AppleScript, even under the “Basic” heading:
properties, loops, references, indexes, arrays, handlers, and much
more. As I said, I’ll point you to resources that can teach you this stuff.
For our purposes, I wanted to make sure you could decode at least a bit
of what’s going on in our example scripts, to which I now turn.

Find and Run Example AppleScripts


Here are some simple scripts to try. To use one, copy and paste (or
retype) it into Script Editor and click the Run button.

213
Tell me how many files and folders are on my desktop:
tell application "Finder"
set theFolder to (path to desktop) as string
set theCount to number of items in folder theFolder
display dialog theCount
end tell

Speak the current date:


set theDate to current date
set theYear to year of theDate
set theMonth to month of theDate
set theDay to day of theDate
set niceDate to theMonth & " " & theDay & ", " & theYear as text
say niceDate

Apply some styles to a word in TextEdit:


set theStyle to {font:"Times", color:{26214, 0, 36237}, size:42}
tell front document of application "TextEdit"
set properties of second word of first paragraph to theStyle
end tell

Resize the frontmost Safari window:


tell application "Safari"
activate
if front window exists then
set bounds of front window to {0, 0, 1000, 600}
else
display dialog ("Safari has no open windows.")
end if
end tell

214
Do a bit of simple math:
set firstNum to text returned of (display dialog ¬
"Enter a number." default answer "")
set secondNum to text returned of (display dialog ¬
"Enter a number." default answer "")
set operation to button returned of (display dialog ¬
"What do you want to do with those two numbers?" ¬
buttons {"Add", "Subtract", "Multiply"})
-- AppleScript dialogs can have a maximum of 3 buttons
if operation is "Add" then
set theResult to firstNum + secondNum
else if operation is "Subtract" then
set theResult to firstNum - secondNum
else
set theResult to firstNum * secondNum
end if
display dialog "The result is: " & theResult

A quick web search should turn up thousands of AppleScripts that you


can use—and I refer you to some additional sources ahead, in Learn
More About AppleScript.

You can also find a bunch of sample scripts already on your Mac, in
the /Library/Scripts folder. You’ll notice that those scripts—and
perhaps many of those you find online—aren’t just text; they’re
AppleScript files. One way to use any of these is to double-click the file
(which opens it in Script Editor) and then click the Run button. (For
scripts located in /Library/Scripts, you’ll be prompted to click a
Duplicate button before your script runs so that changes can be saved.)
But that’s not the only way!

Another way to access an AppleScript saved as a file is to choose its


name from the AppleScript menu (Figure 71). Don’t see it? Open
Script Editor, go to Script Editor > Preferences > General, and select
the Show Script Menu in Menu Bar checkbox. By default, that shows
all the scripts in /Library/Scripts as well as ~/Library/Scripts, so you

215
can add to the menu by placing your scripts in one of those folders (or
a subfolder).

Figure 71: The optional AppleScript menu displays both built-in and
user-supplied scripts, letting you run them with one click (and
without opening Script Editor).

To save any of your own scripts (including those you created using the
sample code just previously) as files, choose File > Save, choose a name
and location, and leave the File Format pop-up menu set to its default
choice of Script. Then click Save.

Save an AppleScript in Other Formats


Besides saving AppleScripts as files (using the Script option in the
Save dialog), you can save them as Applications. These run by
themselves, without opening Script Editor, when you double-click
them in the Finder. (Applications can also behave as droplets, acting
on whatever files or folders you drop onto them.)
Another option is Script Bundle, which is just like an application
except that it can also contain extra resources the script may need
(such as graphics or sounds).
Finally, you can choose Text to save the script as plain text.

216
Tip: Besides running an AppleScript in Script Editor, from the
AppleScript menu, or as standalone apps, you can also trigger
AppleScripts using many of the other utilities discussed in this book,
such as Keyboard Maestro, LaunchBar, and TextExpander.

Edit an Existing AppleScript


One of the easiest ways to learn AppleScript is to start with a script
that someone else has written, make a modification or two, and see
what happens. If you like the results, make further changes, add a few
new lines, or combine portions of multiple scripts. Once you have some
experience fiddling with other people’s code, you’ll feel more comfort-
able creating scripts of your own from scratch.

You might start, for example, with the Resize the frontmost Safari
window script from a few pages back. Try replacing Safari with the
name of another app. Or, try changing this line:

set bounds of front window to {0, 0, 1000, 600}

Those numbers refer, respectively, to the window’s distance (in pixels)


from the left edge of the screen; distance from the menu bar; width;
and height. Change those values to resize or reposition the window.

Then try playing with the front window term. What if Safari has two
windows open? Can you guess how to resize the back window? (It’s
exactly what you think.) Then try changing the text of the dialog that
appears if Safari has no windows open. And so on.

217
Script Debugger: A Better AppleScript Editor
So far, I’ve been talking about Script Editor as though it’s the only
environment in which you can create and run AppleScripts, but it’s
not. There are numerous other tools (including Automator, Keyboard
Maestro, Shortcuts, and other utilities) that let you enter, edit, and
execute AppleScript code. And for basic scripts, any of them will do
nicely.
But when you get to the point of needing to create long, complex, or
tricky scripts, you should use an editor with more power and flexibili-
ty. There’s really no competition here—the script editor AppleScript
pros use is called Script Debugger.
Script Debugger is to Script Editor as Nisus Writer Pro is to TextEdit.
Sure, both tools will format your scripts, show you results, and let
you save them in various formats. But Script Debugger goes way
beyond that. For example, it offers the following features:
✦ Debugging: As the name suggests, Script Debugger’s forte is
helping you find and fix bugs in your scripts—for example, by
stepping through a script one line at a time and seeing the values
of variables and the results of actions at every step.
✦ Explorer: Go way beyond an app’s AppleScript dictionary to see
the exact objects and properties that currently exist in the app and
its open documents. This makes it way simpler to write scripts
that access those objects and properties.
✦ Clippings: Insert frequently used code blocks with a click or two.
✦ Code Folding: Temporarily collapse individual blocks of code to
make it easier for you to see the overall flow of your script.
✦ AppleScriptObjC Code Completion and Debugging: If you use
AppleScriptObjC to write Cocoa apps using AppleScript (see Writ-
ing Cocoa Apps with AppleScript), these features will make the
process much simpler.
That’s just the beginning—Script Debugger offers a long list of addi-
tional powerful features. It’s overkill for beginners, but anyone who
writes more than a modest amount of AppleScript code will find the
savings of time and effort to be well worth the cost of the app. (And
you can save 15% with the coupon at the end of this book!)

218
Tip: If an AppleScript that used to work in an older version of macOS
no longer does, you might just have to open it and re-save it in Script
Editor to re-authorize it. Glenn Fleishman explains in How to use
Script Editor to re-authorize a balky AppleScript in macOS Catalina
and later.

Use GUI Scripting


Sometimes an app doesn’t have an AppleScript dictionary at all. Or, it
does, but it’s completely inadequate for your needs. In that case, you
may be able to work around the problem using GUI scripting, which
instructs AppleScript to simulate mouse clicks, button presses, menu
commands, and the like—“playing” the user interface, as it were. It’s
not foolproof, but it can solve otherwise intractable problems.

In GUI scripting, your script sends commands via a hidden app called
System Events. System Events, in turn, tells a particular app (or other
process) to click buttons, press keystrokes, and so on. (You’ll need to
enable each app individually in System Preferences > Security &
Privacy > Accessibility before they’ll respond to GUI scripting; this
applies both to the target app and to apps that run scripts, such as
Script Editor and Script Debugger. See Deal with the Mac’s Evolving
Security Features for more details.)

For example, I wanted a way to drive an OCR (optical character recog-


nition) app called Readiris with an AppleScript. Readiris is not script-
able, but I was able to use GUI scripting to simulate button clicks and
menu selections, which produced the necessary end result. Here’s a
simplified version of the portion of the script that does that:

219
tell application "System Events"
tell process "Readiris"
click button "OK" of sheet 1 of front window
click menu "File" of menu bar 1
click menu item "Export Document..." of menu ¬
"File" of menu bar 1
end tell
end tell

As you can see, as long as you can tell System Events precisely where to
find a certain button or menu item, you can produce a click. (You can
also send a keystroke with a command like keystroke "n" or keystroke
return.) The problem, however, is that it’s often extremely difficult to
ascertain the hierarchy of objects leading to the one you want—and
worse, sometimes objects don’t respond to names at all.

Here, for example, is an actual line from an AppleScript I wrote:

click button "Convert to Text" of group 4 of group 12 of group 1 ¬


of group 1 of group 3 of group 1 of group "Tools" of group 1 ¬
of group 1 of group 1 of front window

Wow. So…how did I figure that out? Since nothing in the visible user
interface tells me the names or numbers of all those groups of ele-
ments, how did I arrive at that hierarchy? Well, I used magic, which in
this example was packaged into an app called UI Browser.

Among other capabilities, UI Browser lets you browse through any


app’s hierarchy of objects (Figure 72)—something Script Debugger
also does, albeit in a somewhat different form. But what makes UI
Browser special is that it also lets you hover over any part of an app’s
interface and see, in real time and from the perspective of System
Events, what any object is called and exactly the path of containers that
leads to it. It’s the easiest way I know to figure out how to script other-
wise unscriptable apps.

220
Figure 72: Browse an app’s hierarchy of UI objects in UI Browser.

In the previous version of this book, I reported that the app was being
discontinued because its developer, Bill Cheeseman, was retiring, the
app. However, Bill was able to hand the project over to Script Debug-
ger developer Late Night Software, so it’s still available for download.
In addition, the partially completed version 4 of the app (a rewrite
using Swift) has been made open-source. Although version 4 is missing
a lot of features, perhaps some enterprising developers will take it
upon themselves to finish it.

With or without the use of UI Browser, I should warn you that some
apps defy even GUI scripting, usually because they’re little more than
wrappers around custom web browsers. For example, GUI scripting
won’t get you anywhere with the team communication app Slack. What
appear to be links and icons in the app are just part of a monolithic
window as far as System Events is concerned. (In such cases, you may
be still able to take a brute-force approach to automation, by simulat-
ing clicks at certain coordinates, but for such tasks I’d use something

221
like Keyboard Maestro before trying to do something similar with
AppleScript.)

To learn much more about GUI scripting, read the page Graphic User
Interface (GUI) Scripting at Mac OS X Automation.

Use AppleScript Folder Actions


A folder action is an AppleScript that runs automatically when some-
thing happens to a specified folder—you open or close it, say, or add
files to it. For example, a folder action could watch for newly scanned
PDF files appearing in a certain folder and send them to your favorite
OCR software to recognize the text in them and save them as search-
able PDFs.

Not just any old AppleScript can be a folder action; it must be written
specially for that purpose. (For details, see the Folder Actions Refer-
ence page on Apple’s Developer site.)

In addition, before you can use folder action scripts, you must enable
the systemwide Folder Actions capability (if you haven’t previously
done so) and attach a particular script to the folder where your incom-
ing scans are stored. Here’s how:
1. Make sure whatever script you want to use is stored in the /Library/
Scripts/Folder Action Scripts folder or in ~/Library/Scripts/
Folder Action Scripts.

2. Right-click (or Control-click) on the folder you want to attach the


script to, and from the contextual menu that appears, choose Folder
Actions Setup (if you don’t see it at the top level of the contextual
menu, look on the Services submenu). Folder Actions Setup opens.

Note: You may see one or more security alerts when Folder Actions
Setup opens for the first time (see Deal with the Mac’s Evolving
Security Features). Just agree to them and move on.

3. In the dialog that appears, select the script you want to use.
(Although you can attach multiple AppleScripts to a single folder, I

222
don’t recommend it. Pick a single script, and if need be, you can
return to this dialog and change it later.)

4. Make sure Enable Folder Actions is checked at the top of the Folder
Actions Setup window. Your window should look something like
Figure 73.

Figure 73: You’re looking for approximately this end result (folder
and script names may differ) after configuring Folder Actions.

5. Quit Folder Actions Setup.

Now, to use your folder action, drop a new file in the folder (or take
whatever other action(s) the script supports, such as changing or
removing files). The script should run automatically.

Tip: An alternative way to get much the same effect as a folder


action is to set up a rule in Hazel (see Organize Files with Hazel). Yet
another approach is to Use Launchd to Watch a File or Folder.

Here are a few further examples of things you could do with an Apple-
Script folder action:
• Get an alert when someone puts a new file in a shared folder.

223
• Rename all the files dropped into the folder to follow a particular
format or convention.

• Upload the files to a web server.

• Move files to other folders on your Mac depending on file type,


name, or other characteristics.

Writing Cocoa Apps with AppleScript


If you know a little about Objective-C and Cocoa, you can use a
technology called AppleScriptObjC (short for AppleScript/Objective-C)
to access Cocoa frameworks from AppleScript. You can learn more
about it on the Resources for AppleScriptObjC page at Mac OS X
Automation.

Learn More About AppleScript


I’ve barely scratched the surface of what you can do with AppleScript.
If you want to learn more, allow me to recommend a few references:

• Apple’s official Introduction to AppleScript Language Guide

• The AppleScript portion of the excellent Mac OS X Automation site

• MacScripter.net, an extensive discussion forum where anyone


(regardless of skill level) can offer or receive help with AppleScript

• Matt Neuburg’s book AppleScript: The Definitive Guide

• AppleScript 1-2-3, by Sal Soghoian and Bill Cheeseman

• A Wave of Automation at Mac OS X Automation, which covers


automation features added in Mavericks (including AppleScript
libraries)

• OS X Yosemite & Automation at Mac OS X Automation, which


covers automation features added in Yosemite (and is still applica-
ble)

224
Tip: Although AppleScript (as discussed in this chapter), JavaScript
(discussed ahead in Use Omni Automation), and Swift (discussed
back in Using Swift for Automation) are Apple’s official languages for
automating your Mac, you can choose other languages! For example,
an easy-to-learn language called Lua can also automate your Mac if
you install a free tool called Hammerspoon.

225
Script the Command Line
with Shell Scripts
As you probably know, macOS is based on Unix, and as such, there’s a
whole layer of functionality most users never see. But you can access a
long list of hidden files and useful tools in the text-based world of the
command line.

A command-line interface is a way of giving instructions to a computer


and getting results back. You type a command (a word or other se-
quence of characters) and press Return or Enter. The computer then
processes that command and displays the result (often in a list or other
chunk of text). In most cases, all your input and output remains on the
screen, scrolling up as more appears. But only one line—usually the
last line of text in the window, and usually designated by a blinking
cursor—is the actual command line, the one where commands appear
when you type them.

You normally access the command line on a Mac using the Terminal
utility (found in /Applications/Utilities). When you open Terminal, it
runs a special program called a shell, which interprets the commands
you type and delivers the text-based output. macOS comes with several
different shells, but that detail is unimportant for our purposes.

What is important is that shells are programmable. You can put a


series of shell commands in a text file and, without any special fuss,
run it as a program. Shell scripts can automate nearly any activity you
can perform on the command line. Although some scripts are fabu-
lously complex, running many thousands of lines, we’re concerned
here with simpler tasks you can automate.

If you happen to be the sort of person who genuinely likes working in a


command-line interface, you’ll probably want to have lots of scripts
that simplify the process for you. But even if you’re entirely happy
remaining in the Mac’s graphical interface, shell scripts can be your

226
friends. They can modify files and folders, perform system functions,
and do other sorts of tricks that are difficult or impossible to perform
in other ways (such as using AppleScript or Automator). In fact, some
of my favorite AppleScripts, Automator actions, and Keyboard Maestro
macros rely heavily on embedded shell scripts.

Here are a few things shell scripts can do for you:

• Modify hidden preferences for macOS and its apps

• Securely delete specific files or folders without first moving them to


the Trash

• Force background processes to quit without requiring the use of the


Activity Monitor utility

• Load or unload daemons and agents, which control scheduled and


background tasks (see Apple’s developer guide Creating Launch
Daemons and Agents)

Ordinarily, you create and run shell scripts in the Terminal utility (as I
show you next). However, as I mentioned, many of the other utilities I
cover in this book can run shell scripts too.

Tip: If you’d like to know all about the command line—how to get
around, run programs, edit files, and (of course) work with shell
scripts, pick up my book Take Control of the Mac Command Line with
Terminal.

Create Your Own Shell Script


I want to give you a tiny taste of creating your own shell scripts. As
with the other topics in this chapter, I’m not going to teach you any-
thing about programming as such, just the mechanics of creating and
using a simple shell script. I want you to have enough familiarity with
the process that you can successfully reproduce and run shell scripts
you may run across in magazines, in books, or on websites.

You can create and run a shell script in six easy steps.

227
Step 1: Open Terminal
Open the Terminal utility (in /Applications/Utilities). You’ll be
presented with a mostly blank window. That’s where all the magic
happens.

Step 2: Start with an Empty Text File


Scripts are plain text files, so you should begin by creating one in a text
editor. You can make a shell script in TextEdit, BBEdit, or even Word,
but that requires extra steps. So I suggest using a simple command-
line text editor called nano.

For the purpose of demonstration, we’ll name the script test.sh.


(The .sh extension isn’t mandatory, but it can help you keep track of
which files are scripts.) Before you create this file, I suggest typing cd
(change directory) followed by Return to ensure that you’re in your
home directory. (You can put scripts anywhere you want, but for now,
this is a convenient location.)

That done, type nano test.sh and press Return.

The nano text editor opens with a blank file.

Step 3: Type In the Script


A script can be anything from a single one-word command to
thousands of lines of complex logic. Let’s start with a very simple, five-
line script. Type this:

#!/bin/zsh
echo "Hello! The current date and time is:"
date
echo "And the current directory is:"
pwd

The first line tells the script which shell program to use (in this case,
bash). The two echo commands simply put text on the screen. The date
command displays the date (surprise!), and the pwd (print working
directory) command displays your current directory. So, this script

228
displays four lines of text, two of which are static (the echo lines) and
two of which are variable.

Step 4: Close and Save the File


To save the file, press Control-O and press Return to confirm the file
name. Then press Control-X to exit nano.

Step 5: Enable Execute Permission


The only slightly tricky thing about running scripts—and the step
people forget most often—is adding execute (run) permission to the
file. To do this, enter chmod u+x test.sh.

Step 6: Run the Script


That’s it! To run the script, type ./test.sh and press Return. The
window should display something like this:

Hello! The current date and time is:


Wed Jun 1 19:58:21 CST 2022
And the current directory is:
/Users/jk

For fun, try switching to a different folder. For example, type

cd /Library/Preferences

and press Return to move to the /Library/Preferences folder.

Now run the script again by typing ~/test.sh and pressing Return.
You’ll see that it shows your new location.

Tip: Any time you need to put a new script on your system, follow
these same steps (although the script name and location may vary).

229
Try Another Script
Here’s another script you may find handy. It generates a random
integer within a range you specify.

Note: An earlier version of this book had a script for renaming a


batch of files in this spot, but since that capability was built into the
Finder starting in Yosemite (see How to Batch Rename Files in OS X
10.10 Yosemite by Josh Centers in TidBITS), I’ve replaced it with
something the Finder can’t do.

Repeat the preceding set of directions, with three differences. First, in


step 2, use a different filename when you open nano:
nano random.sh

Then, in step 3, type the following code instead:


#!/bin/zsh
range=$(( $2 - $1 + 1 ))
echo "Your random number is:" $(( (RANDOM % $range) + $1 ))

And finally, in step 5, you’ll enter chmod u+x random.sh.

To run this script, enter ./random.sh followed by the lowest possible


number, a space, and the highest possible number. For example, to
generate a random integer between 0 and 50, inclusive, enter this:
./random.sh 0 50

Tip: To learn more about shell scripting, read Apple’s Shell Scripting
Primer.

Shell Scripts Outside the Shell


But wait! What if you want to do something that requires a shell script,
such as generating random numbers, frequently—without having to
mess around in Terminal? You can put a script like that in a launcher
(like LaunchBar), a text-expansion tool (like TextExpander), or a

230
macro utility (like Keyboard Maestro), so that you can execute it with
just a keystroke or click—just as you can with AppleScript and Java-
Script. In fact, although Terminal is useful for experimenting with
scripts in real time, most apps that can run shell scripts let you type or
paste them in the app directly.

231
Run Actions Automatically
Recently I was setting up some background apps on one of my Macs to
run every time I restart the computer and to relaunch automatically if
they crashed. I was struck with the realization that, in earlier editions
of this book, I had never explained how to do things like that—for all
the examples of automation I gave, nearly all of them assumed that
automated tasks would be triggered manually.

Let’s correct that! In this chapter I tell you about various ways you can
get things to happen all by themselves on your Mac: after the initial
setup there are zero clicks, keystrokes, or button presses required.

To be sure, other parts of this book already discuss ways of getting


certain things to happen on their own. Hazel (see Organize Files with
Hazel) and AppleScript folder actions (see Use AppleScript Folder
Actions) can move or otherwise act on files when they appear in a
designated folder. Mail rules (see Manage Incoming Apple Mail with
Rules) run automatically when a new message arrives. Both Better-
TouchTool (see Use BetterTouchTool) and Keyboard Maestro (see
Control Your Mac with Keyboard Maestro), can run macros on a
schedule or in response to various system events.

While all those mechanisms are useful, what I cover in this chapter are
tools built into macOS that enable you—potentially without installing
any extra software—to trigger arbitrary actions of nearly any kind just
when they need to happen; and, more specifically, trigger them in
situations that may be inaccessible to those other methods.

For example:

• Run a certain program when your Mac restarts, regardless of which


user logs in.

• Open your favorite browser when you log in, but not when another
family member does.

• Speak a message whenever someone adds a file to a shared folder.

232
• Copy files for a project you’re working on to a network server
whenever you mount that volume in the Finder.

• Open the Pages document containing materials for the class you’re
teaching whenever your office hours begin.

• If your Mac is functioning as a server, make sure any relevant apps


(such as a web server or database server) run as soon as the Mac
(re)starts and relaunch automatically if they happen to crash.

• Open Excel, QuickBooks online (in a web browser), and Calculator


at 9 A.M. on the one or two days a month you have to do accounting
tasks for your small business.

In some cases, there are multiple ways to trigger actions like these, and
you should pick whichever one you like best. Before choosing a
method, I suggest acquainting yourself with all the options.

Use Login Items


Let’s begin with the simplest approach, which is adding something to a
list of items macOS opens automatically when you log in. Chances are,
quite a few apps you’ve installed already have either done this them-
selves (with your approval) or asked you to do so. You can find Login
Items in System Settings or System Preferences:

• macOS 13 Ventura or later: Go to System Settings > General >


Login Items.

• macOS 12 Monterey or earlier: Go to System Preferences >


Users & Groups > Login Items.

Tip: Later on I explain how to use a Keyboard Maestro macro to open


the Login Items pane with a single keyboard shortcut; see Macro #1:
Open Login Items.

Once there, you’ll see something like Figure 74.

233
Figure 74: The Login Items list in System Settings shows all the
items that open on every login for the current user.

To add something to this list, you can either drag it in from the Finder
or click the plus button, navigate to the item, and click Open. Al-
though applications are the most common item to open at login, you
can also add a file, folder, or volume—anything you can select in the
Finder. To remove an item from the list, select it and click the minus
button.

Login items apply to the currently logged in user only. So, if your Mac
has multiple users, each with a separate account, each person’s list of
login items will likely be completely different.

Be aware that your Mac might also open other items on login that
aren’t on this list! For example, when you restart or shut down your
Mac (using Apple  > Restart or Apple  > Shut Down), if “Reopen
windows when logging back in” is checked (Figure 75), whatever apps
and windows were open when you restarted or shut down will reopen
when you log back in, putting you approximately where you left off.

234
Figure 75: If “Reopen windows when logging back in” is checked,
your Mac will reopen any currently open apps and their windows
when you log back in.

It can be handy to have your favorite apps, documents, and folders


open whenever you log in, but if you need items to open at other times,
read on for more ideas.

What Happened to StartupItems?


If you’ve been using macOS since the days when it was called Mac
OS X, you may remember a StartupItems folder, which could contain
items that would open on startup, regardless of which user logged in.
In fact, there were two such folders: one in /System/Library (for
items Apple added) and one in /Library (for items you—or an app
you use—added). Those folders still exist, and you may even find
items from older apps stored there. Although these folders still work,
Apple has been urging developers for some time to instead rely on
launchd to open items at startup. See Use Launchd, ahead, for details.

Use Calendar Events


A second mechanism for opening items at specific times is hidden deep
within Apple’s Calendar app. Whenever you create a scheduled event,
you can add one or more alerts to it. Most people use the default
Message with Sound alert, which does what it says on the tin. But if
you dig a little deeper, you can find two other actions Calendar can
take when it’s time for an event: send an email or open a file. For the

235
purposes of this book, I’m going to ignore the email option (though you
should absolutely experiment with it if it’s of interest to you) and focus
on opening files.

I think Apple’s intention behind this feature was to let Calendar open
documents related to an event—for example, opening an agenda when
a meeting begins or a tax return when you have a scheduled call with
your accountant. You can certainly use it that way, but you can also
have this mechanism open something at a particular time without
there being any actual meeting or event connected to it. Opening the
item itself can be the event.

To create an event that opens a file, follow these steps:

1. In Calendar, create a new event in any manner; for example, by


choosing File > New Event or by double-clicking in an empty spot
on the calendar.

2. Fill in a name, date, and time for the event as usual in the popover
that appears (Figure 76).

Figure 76: Start by entering normal event details.

236
3. From the “alert” pop-up menu, choose Custom. A tiny extra window
appears above the popover (Figure 77).

Figure 77: This extra window appears when you choose Custom.

4. From the pop-up menu labeled “Message with sound,” choose


“Open file.” Another pop-up menu appears below it, initially show-
ing “Calendar” (Figure 78).

Figure 78: Instead of “Message with sound,” choose “Open file.”

5. Now, from the new pop-up menu labeled Calendar, choose Other.
Navigate to the item you want to open and click Select. Although
Calendar uses the word “file,” it can also be an app (or even an
AppleScript or Automator action saved as an application)! Whatev-
er you select will open when the time of the event arrives, exactly as
if you had double-clicked it in the Finder.

6. Optionally, click the pop-up menu labeled “At time of event” and
choose an earlier or later time.

7. Click OK.

That’s it! When the time comes, the item opens; for recurring events, it
opens each time. You can also, if you like, add multiple alerts to the
item—in addition to opening an item it could also show a message and
play a sound, for example.

237
Tip: To learn much more about the ins and outs of Calendar, read
Take Control of Calendar and Reminders by Scholle McFarland and
Glenn Fleishman.

Use Launchd
If you want vastly more control over when and how something runs,
there’s yet another option. macOS has a built-in, systemwide mecha-
nism called launchd (short for “launch daemon,” where daemon, in
computer-speak, is a program that runs in the background). In con-
trast to simpler auto-launch tools like cron, available in every flavor of
Unix and Linux, launchd is enormously flexible and powerful. It has the
capability to run apps, shortcuts, and scripts of all kinds automatically
in a variety of circumstances.

For example, launchd enables your Mac to run things:

• When you start (or restart) your Mac

• When any user logs in

• When a specific user logs in

• When a volume is mounted in the Finder

• When the program launched by the launchd item has crashed

• When a file or folder changes

• On a fixed schedule (such as every 12 minutes, every Tuesday and


Friday at noon., or every March 7th at 7:23 A.M.)

What can be launched? Pretty much anything: ordinary apps, shortcuts


created by the Shortcuts app, AppleScripts, Automator actions, shell
scripts, and so on. In fact, you’ve been using launchd for as long as
you’ve been using macOS—perhaps without even realizing it—because
lots of apps and system utilities install their own launchd items, and
macOS includes about 800 launchd items for its own purposes!

238
And to unleash all this power, the only configuration tool you need is…
a text editor. Any text editor. TextEdit will do just fine, as will BBEdit
or nano on the command line—anything that can edit and save plain
text files.

Well, OK. I’ve left out a few tiny details.

First, these files, which have to be given names following a strict and
unusual pattern, must also be saved in very specific places (discussed
just ahead), and they behave differently depending on which folder you
put them in.

Second, these text files have to be crafted just so, and even the tiniest,
most seemingly inconsequential error can cause launchd to give up
without so much as an error message, causing untold confusion. (I
speak from experience here.)

And third, you need to use Terminal commands or a third-party app if


you want to load or unload these actions without restarting your Mac
or logging out and back in. That live loading or unloading is an impor-
tant part of testing new actions.

So, while I’ll give you a quick introduction to creating and using some
simple launchd items manually—just to show you that it can be done—I
recommend strongly that you pay a few bucks for an app that will
make the process vastly simpler and less error-prone if you want to do
anything beyond the very basics; I discuss these a bit later.

Agents and Daemons


No, I’m not talking about a Dan Brown novel. For reasons known only
to Apple, macOS makes a hair-splitting distinction between two types
of launchd items: agents and daemons. You create both in exactly the
same way, but you store them in different folders. The folder where the
item is stored determines both when it loads and which user account
“owns” the process. For Apple, an agent is a launchd item that loads
under the ownership of a regular user upon login, while a daemon is a
launchd item that loads as the root user (though you can override this)
on startup.

239
I should clarify the word “load” here. A launchd item might be config-
ured to run an app on a schedule or in response to some other event.
But macOS has to have previously loaded it—read its file and sched-
uled what’s supposed to happen. Loading normally happens either at
startup or at login. The fact that a launchd item loads does not neces-
sarily mean that the action it contains runs immediately, though that’s
one possible configuration.

Here are the locations of the special folders macOS monitors for the
presence of launchd items, and how they behave:

• /System/Library/LaunchAgents: Items load when anyone logs in.


Owner: currently logged-in user. Items in this folder are part of
macOS, and only Apple can make changes.

• /System/Library/LaunchDaemons: Items load on startup. Owner: root,


unless overridden to be a particular user. Items in this folder are
part of macOS, and only Apple can make changes.

• /Library/LaunchAgents: Items load when anyone logs in. Owner:


currently logged in user.

• /Library/LaunchDaemons: Items load on startup. Owner: root, unless


overridden to be a particular user.

• ~/Library/LaunchAgents: Items load when you, the user who added


them, log in. Owner: you.

Since the first two folders can be modified only by Apple—due to the
system being an immutable, locked volume for several releases—you
need concern yourself only with the last three. In many situations,
which user owns a process is irrelevant. And if you’re the only person
using your Mac, the behavior of the three will be nearly indistinguish-
able. But, to clarify a bit further:

• If you want something to load only when you log in, and not when
any other user of your Mac logs in, you want a launch agent that
you’ll store in ~/Library/LaunchAgents.

240
Note: This may sound like Login Item, discussed earlier in this
chapter. Although both mechanisms can open an item on login,
launch agents are far more flexible. They can include not just files,
folders, volumes, and apps, but also command-line programs and
scripts; plus, they have far more options (such as restarting automat-
ically if they crash).

• If you want something to load when any user logs in, and have it run
under that user’s ownership, that’s also a launch agent; it goes
in /Library/LaunchAgents.

Launch agents, whether stored in ~/Library/LaunchAgents


or /Library/LaunchAgents, can interact with your Mac’s GUI (graphi-
cal user interface); for example, they can open windows and ask for
input.

• If you want something to run after startup, regardless of who logs


in, and to run with root (administrative) privileges, you should store
it in /Library/LaunchDaemons. That makes it a daemon, and although
root privileges give it more power (for example, the capability to
modify anyone’s files), it can’t access your Mac’s GUI.

Note: Many, many apps also include their own launchd items bundled
within the apps themselves. Although these items can have the same
capabilities as regular launch agents and launch daemons, you won’t
interact with them or modify them yourself. So, I’m ignoring those in
this chapter.

Create a Launchd Item


I’ve told you how launchd items (agents or daemons) can behave and
where they go. Now let’s fill in the rather significant piece of what’s
actually in these mysterious text files!

Launchd items are stored as property lists, which end in the


extension .plist. You’ve probably heard of plist files, because the
settings/preferences for macOS itself and all your apps are also stored
as plists. You may have read about, or even tried, various defaults

241
write commands to modify some hidden preference; what that actually
does is change the contents of a .plist file.

Tip: To learn much more about using defaults write and making other
low-level modifications to your Mac, be sure to check out my book
Take Control of the Mac Command Line with Terminal.

Property list files, in turn, are written using a markup language called
XML (for eXtensible Markup Language). If you’ve ever edited an
HTML file, XML will look extremely familiar! It consists of tags sur-
rounded by angle brackets (<>) and following a specific structure.
Here’s a very simple example launchd item:

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.takecontrolbooks.example</string>
<key>Program</key>
<string>/Users/jk/Documents/test.sh</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Let’s break this down:

• The first four lines (the ones starting with <?xml, <!DOCTYPE, <plist,
and <dict>) and the last two lines (</dict> and </plist>) are always
going to be exactly the same in every launch item, so you can simply
copy and paste them, but otherwise, you don’t have to worry about
their contents.

• The middle section, between <dict> (dictionary) and </dict>, is


where the interesting stuff is. You’ll notice there are, in this exam-

242
ple, three pairs of lines—each one a key (something surrounded by
<key> </key> tags) and a value (whatever comes immediately after
the key).

• The first key, which is mandatory, is Label. It tells macOS what the
name of the action is. The name is specified in the following line,
between <string> </string> tags, and you’ll notice that it looks like
a backwards domain name. That’s because it follows reverse do-
main notation. In reality, this string can be anything you like, as
long as it’s unique on your computer.

You don’t have to own a domain name, and Apple isn’t going to
check to see that it’s formatted correctly. But, just so it’s easier to
find your own launchd items, I suggest naming them all with the
same starting bit—for example, local.joe or com.yourname. The last
bit, after the fake domain name and a period, identifies this specific
launchd item. Here, it’s just example.

Note: When you save the file, you should give it the same name as
its label, but add .plist to the end. So this text file would have the
filename com.takecontrolbooks.example.plist.

• The second key is Program, which—shocker!—tells macOS what pro-


gram to run! Once again, that program is specified inside <string>
</string> tags on the next line. You’ll notice that the program string
is a complete pathname. You can’t include shortcuts like ~
(for /Users/you), relative pathnames, aliases, or symbolic links.
Even though you might not need a full pathname when running
something in the Finder or in Terminal, it’s mandatory here. In this
example, I’m imagining that I wrote a shell script (see Script the
Command Line with Shell Scripts) called test.sh and stored it in
the Documents folder of my home folder (username jk).

In this example, the command has no arguments (that is, no addi-


tional parameters after the initial command). If it did, you’d have to
construct the file differently; see Run a Command-Line Program
with Arguments.

243
• The final key in this example is RunAtLoad, which predictably tells
this launchd item to run the program when the item loads. (Remem-
ber, when it loads is determined by where the .plist is stored.)
Since RunAtLoad is a Boolean (yes/no) value, it’s not followed by a
string but rather by <true/>, which simply says, yes, do run this
when the item loads.

Not too bad, right? If you created a file like that and stored it in
~/Library/LaunchAgents, macOS would load it when you log in and,
because they only parameter we set concerning when it should run was
RunAtLoad, it would run the test.sh script and then become dormant
until the next time you log in. (Refer to the list a few pages back for
other places you might store the file.)

So far so good, but what if you want to do something just a wee bit
fancier? Launchd has dozens of options, and I’ll mention just a few
major ones to get you started.

Tip: If you want an extensive tutorial on launchd, check out


launchd.info, a free site by the developer of LaunchControl, which I
describe later. Although the site is extremely educational, I think its
real purpose is to say, “Look how complicated this all is! Wouldn’t you
rather buy our app to make this so much easier?” And honestly, I
can’t disagree with that sentiment.

Run a Command-Line Program with Arguments


If you’re running a command-line program or script that takes argu-
ments (additional parameters beyond the name of the program itself),
then instead of putting those after a Program key, you’d put them after a
ProgramArguments key. On the command line, arguments are separated
by spaces, with some arguments taking values. For example, let’s say I
wanted to pass the -e argument to the open command with the
value /Users/jk/Desktop/example.txt. I would write it like this:

open -e /Users/jk/Desktop/example.txt

Although that would work fine in Terminal (assuming you had a file
with that name in that location), it wouldn’t work in a launchd item
unless you wrote it like this:

244
<key>ProgramArguments</key>
<string>/usr/bin/open</string>
<string>-e</string>
<string>/Users/jk/Desktop/example.txt</string>

So, not only does each element that’s preceded by a space require a
separate line, but we must also start by specifying the full pathname
for the program itself (in this case, /usr/bin/open).

Open an App
Ordinary apps on your Mac, such as those stored in your Applications
folder, are not single files (even though they appear to be). In reality,
they’re special folders called bundles, containing a bunch of other files
and folders.

Tip: You can view the contents of an app by right-clicking or Control-


clicking it and choosing Show Package Contents from the contextual
menu.

As such, launchd can’t run an app simply by pointing to the app’s name
as it appears in the Finder, because—going back to the rule that path-
names must be complete—launchd requires the path to the actual
executable file within the app bundle, and that pathname must also
include the app’s full name with extension.

For example, in the Applications folder you’ll find Mail, but if you were
to turn on extensions (by going to Finder > Settings/Preferences >
Advanced and checking “Show all filename extensions”), you’d see it’s
really Mail.app. If you then dug through the package contents you’d
find that the executable, called Mail, is nested two levels deep inside
Contents/MacOS. Even then, because Mail is part of macOS, it’s not
really stored in /Applications (even though its icon appears there), but
rather in /System/Applications!

So, the full path to Mail, if you wanted to open it with launchd, would
be /System/Applications/Preview.app/Contents/MacOS/Preview.

But wait! If you enter that pathname as a program value, you’ll get an
error message, because…launching a GUI app like preview requires the
245
use of the open command along with the -a flag! And so, because that’s
a command-line program with arguments, the actual command to
open Mail would be:

<key>ProgramArguments</key>
<string>/usr/bin/open</string>
<string>-a</string>
<string>/System/Applications/Mail.app/Contents/MacOS/Mail</string>

All that to say: launchd can absolutely launch regular apps, but in order
to find the executable file, you might have to do a bit of exploring.

Watch a File or Folder


Rather than running a program when the launchd item loads or on a
schedule, launchd can watch a particular file or folder and run a pro-
gram when that item changes. Add this to the file:

<key>WatchPaths</key>
<array>
<string>/full/path/to/folder_or_file</string>
</array>

If the pathname is for a single file, the program runs when that file is
created, deleted, or modified. If the pathname is for a folder, the
program runs when the folder is created or deleted, and when any file
in the folder (at the top level only) is created, deleted, or modified.

Note: If you use WatchPaths, you’ll most likely want to omit RunAtLoad
(or set it to <false/>).

Restart a Program After a Crash


Suppose you’re using launchd to open a program that must be running
in the background all the time, such as a web or database server. Any
app can crash, and if that happens to a mission-critical program, you’ll
probably want it to relaunch itself immediately afterwards. If you’ve
already set up a launchd item to open the app, you can add the follow-
ing to make it reopen after a crash:

246
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<true/>
</dict>

Notice that it’s not merely a question of whether to keep the program
alive, but one that requires the additional parameter of Crashed (which,
since it’s set to true, means that the program has indeed crashed).
Launchd can also check for other states that would cause the program to
reopen, such as another program running or the availability of a
certain network. Refer, again, to launchd.info for details.

Run at an Interval
Instead of (or in addition to) running when the launchd item loads,
would you like your program to run every minute, hour, day, or other
regular interval? Add this:

<key>StartInterval</key>
<integer>3600</integer>

The integer you enter (replacing 3600) is the number of seconds be-
tween launches. So, use 3600 to open something every hour, 86400 to
open it once a day, and so on.

Note: You can also schedule jobs to run at specific times and dates;
see launchd.info for how to format those.

Control Launchd Manually


So far we’ve learned that if you create an XML .plist file, make sure its
contents are exactly nitpickingly correct, and store it in one of three
magical folders, it will load at either startup or login and the program
it’s configured to run will launch according to the parameters you set.

But.

What if you’re writing a new launchd item and you want to test it, like,
right now? Knowing how difficult it can be to get all the tags exactly

247
right, you probably don’t want to be forced to restart or log out/in
repeatedly just to test it. Surely there must be a way of telling macOS to
load an item immediately, right? Indeed there is; likewise, there’s a
way to tell launchd to unload an item that would otherwise keep run-
ning indefinitely (or until the next restart/login).

To do things like that, you’ll have to open Terminal and use a com-
mand called launchctl (for “launch control”). Just explaining all the ins
and outs of launchctl could take many pages, and by this point you’re
probably wondering when I’m going to let you off the hook and tell you
about nice, friendly GUI apps for controlling launchd items (which is
very soon). So I’m just going to explain a few basic commands here.

Note: Apple changed launchd significantly in OS X 10.10 Yosemite,


so sometimes you’ll see different commands on blogs or support
forums than the ones described here, such as load and unload. Those
older commands still work, at least as of Sonoma, but the ones I
describe here have a future.

Load or Unload a Launchd Item


You can force an item to load immediately, which also means the
program it opens runs immediately if, and only if, RunAtLoad is true.
Use this command:

launchctl bootstrap gui/`id -u` ~/Library/LaunchAgents/name.plist

Replace ~/Library/LaunchAgents with /Library/LaunchAgents if appro-


priate, and replace name.plist with the filename of the launchd item.

However, if you want to load a launch daemon, you’ll instead use this:

launchctl bootstrap system/ /Library/LaunchDaemons/name.plist

Let me say a few words about that funny-looking string gui/`id -u`.
The gui part tells launchd what kind of login ID follows it, while the
part after the slash is supposed to be your numeric user ID (not your
username). You do know your numeric ID, right? No? Well, if you’re
the only user on your Mac, there’s a pretty good chance it’s 501, in
which case you could say bootstrap gui/501 …. But it might not be! So,
`id -u` allows you to carry out a tiny command within the command:

248
all it does is spit out the numeric ID of the current user. The output of
`id -u` is a number that’s swapped in and directly interpreted by
launchctl. Finally, note that those are backticks (`), on the same
keyboard key as the tilde (~), not apostrophes!

The reason you don’t need all that with launch daemons is that they
run as the root user, and you use system/ as a shortcut to say that.

To unload a launchd item, use exactly the same system, but replace
bootstrap with bootout. For example:

launchctl bootout gui/`id -u` ~/Library/LaunchAgents/name.plist

Start or Stop a Launchd Item


What if you load an item (as just described) but it uses a schedule,
watches a file or folder, or otherwise waits for something to happen
before running its program? If you want to force it to run right now,
even though that condition may not have been met, use this:

launchctl kickstart gui/`id -u`/name.plist

Or, for launch daemons:

launchctl kickstart system/name.plist

As above, replace the filename as necessary. (Notice that you don’t use
the full pathname for starting or stopping, and that there’s no space
before the filename.)

To stop a launchd item that’s currently running, use this:

launchctl kill SIGTERM gui/`id -u`/name.plist

Or, for launch daemons:

launchctl kill SIGTERM system/name.plist

Control Launchd with an App


If you wear your propeller beanie with pride and only grudgingly
consent to use the occasional GUI app, I’m sure you’ll consider it a
badge of honor to memorize and master all the details of creating and

249
using launchd items manually. (And remember, I’ve only barely
scratched the surface here!) If, on the other hand, you’re an ordinary
mortal from Earth with an extra twenty bucks, you can save yourself a
tremendous amount of time and effort by picking up one these:

• LaunchControl (Figure 79; $21.00)

• Lingon X (Figure 80; $19.99)

Figure 79: An example launch agent in LaunchControl.

Figure 80: An example launch agent in Lingon X.

250
Both apps are excellent, helping you unlock the power of launchd and
saving you from making mistakes. They approach this task in different
ways, and one or the other might appeal to you more. You can down-
load trial versions of each and decide for yourself which you prefer. (I
personally gravitate toward Lingon X, which I’ve used for many years,
but that’s just a matter of taste.)

In either case, you can create launchd items by filling in a simple form,
checking some boxes, and choosing menu commands. You can also
load, unload, start, and stop items without having to learn any arcane
command-line incantations. And you can also control—and, in some
cases, edit—launchd items supplied by other apps.

I refer you to the respective apps’ documentation for complete details


on using them, but if you do more than a trivial amount of fiddling
with launchd, I can guarantee that either app will easily pay for itself in
saved time and aggravation.

251
Use Omni Automation
Earlier in this book, I covered a number of apps with built-in au-
tomation tools, such as Microsoft Office and Nisus Writer Pro (see
Automate Individual Apps). I also told you about systemwide plat-
forms such as AppleScript (see Get Started with AppleScript) and
JavaScript for Automation (see Using JavaScript for Automation),
which can be used both for automating individual apps and for cross-
application scripting.

Pro versions of apps made by the Omni Group can already be automat-
ed in any of these ways. Those include OmniFocus Pro (a task manage-
ment app), OmniGraffle Pro (a graphing and charting app), OmniOut-
liner Pro (an outlining app), and OmniPlan Pro (a project management
app). Thus it may seem strange that I’m addressing them in a separate
chapter.

But I felt it was important to give them extra attention because of a


fantastic innovation the company began rolling out a couple of years
ago—something they call Omni Automation.

Note: A site by Sal Soghoian, Voice Control and Omni Automation,


shows you how to use Voice Control in Monterey 12.3 and later with
Omni Group apps.

What Omni Automation Can Do


In simple terms, Omni Automation is an implementation of JavaScript
that (like JXA) permits automation both within and between apps. But
it goes further by working cross-platform between the macOS and
iOS/iPadOS versions of a given Omni app. Write a script for OmniOut-
liner Pro on your Mac, and you can run the same one in OmniOutliner
on your iPad (or vice versa). This is significant, because until now, the
automation tools available for iOS/iPadOS (such as Shortcuts) have
been constrained to just the iOS/iPadOS platform. Now, for the first

252
time, there’s a way to get sort of a little bit close-ish on iOS/iPadOS to
what you’ve been able to do for years with AppleScript on a Mac—and
you can write for both platforms at the same time.

To be sure, I need to make a couple of qualifications here. First, as


terrific as this capability is, it’s still not nearly as extensive or powerful
as AppleScript or JXA on a Mac—partly because of the way iOS/
iPadOS apps are inherently isolated from each other (for important
security reasons), and partly because, as I write this, only three apps
offer this feature.

Second, the most exciting part of Omni Automation is what it does for
iOS/iPadOS—but this book isn’t about iOS/iPadOS automation, except
in a tangential sense.

Even so—and even if you look only at the Mac side—Omni Automation
offers some terrific capabilities:

• Third-party developers (including you!) can use Omni Automation


to create plugins that add new features to Omni apps.

• Plugins can include scripts called actions that are triggered by a


menu command, toolbar button, or another script.

• Scripts can also be encoded as URLs, which means that clicking or


tapping a link on a webpage, in an HTML help document, or in a
PDF document can run a script in an Omni app. URL-encoded
actions can also be attached to individual objects in a document.

• Supported Omni apps include a built-in scripting console which lets


you write your scripts right in the app.

In case you don’t already use OmniFocus Pro, OmniGraffle Pro, Omni-
Outliner Pro, and/or OmniPlan Pro—or if you do, but you’re having
trouble visualizing how these capabilities could be put to practical
use—let me offer some examples of what you could do with Omni
Automation:

• Import list or tabular data from a webpage into a single- or multi-


column OmniOutliner Pro document.

253
• Sort an outline, or retitle columns based on the results of a mathe-
matical calculation.

• Use data from a table on the web to color-code a U.S. map by state
in OmniGraffle Pro.

• Draw a logo programmatically in OmniGraffle Pro. (If you have a


blank document open in OmniGraffle Pro, you can also just click a
link to draw that logo.)

• Create a set of slides in OmniGraffle Pro based on an outline in


OmniOutliner Pro.

• Import the text from an OmniOutliner Pro document into a text box
in OmniGraffle Pro.

You can learn all about Omni Automation, and see exactly how to do
most of these tasks, on the Omni Automation website. The site was
built by the estimable Sal Soghoian, who was formerly in charge of
automation technologies at Apple (see The State of Mac Automation).
It features numerous videos, tutorials, code samples, and other docu-
mentation to get you started.

Although I don’t want to reiterate all that material here, I would like to
offer just a couple of examples of what Omni Automation can do and
how you can get started. Since this is a book about Mac automation, I’ll
be using the Mac version of OmniGraffle Pro for my examples, but the
iOS/iPadOS version is nearly identical, and OmniOutliner offers a
comparable set of features on both platforms.

254
Security and iOS/iPadOS Automation
As I hinted earlier, one of the barriers to systemwide automation on
iOS/iPadOS is the way apps are sandboxed, or isolated from each
other, to prevent hacking, malware damage, and other problems.
That’s just one of numerous restrictions Apple places on iOS/iPadOS
developers in the name of security. Of course, security is an excellent
and admirable goal, so it’s worth wondering whether Omni Au-
tomation somehow subverts these protections.
The short answer is: no. Omni Automation was designed with security
as a prime consideration. Whenever a script is executed that operates
outside an Omni app (including scripts that let OmniGraffle Pro and
OmniOutliner Pro talk to each other, and scripts embedded in URLs),
there’s a review process—you, the user, must explicitly agree to each
and every script usage. (For that matter, Apple would not have
approved the iOS/iPadOS versions of the apps for sale in the App
Store if the company did not believe they contained adequate protec-
tions.)
Even so, it’s never wise to underestimate the creativity of people who
create and distribute malware, so you should install plugins only from
trusted sources—and exercise common sense when tapping links or
pasting in JavaScript code, too.

Try Omni Automation in OmniGraffle


Pro
Sal Soghoian suggested an easy demonstration of how you can see the
JavaScript code for creating shapes in OmniGraffle Pro, and then make
small adjustments to change the shape in real time. To try this, you’ll
need OmniGraffle Pro 7.3 or later (a free trial is available). Follow
these steps:

1. In a blank OmniGraffle document, draw a simple square or rec-


tangle (Figure 81).

255
Figure 81: A basic shape in OmniGraffle Pro.

2. With the shape still selected, choose Edit > Copy As > JavaScript.
This puts the code needed to draw that shape on your clipboard.

3. Now press Delete to delete that shape from your document. (Don’t
worry, we’ll bring it back in a moment.)

4. Choose Automation > Show Console to display OmniGraffle’s con-


sole window. I suggest dragging it to make it a bit larger than its
default size. Make sure you can see the console and your document
window at the same time.

5. Click in the field at the bottom of the window, and choose Edit >
Paste (⌘-V) to paste the JavaScript code in (Figure 82).

256
Figure 82: The JavaScript code for a shape in the console window.

6. Press Return. Your shape should reappear in your document in-


stantly, just as you left it—except this time, it was drawn by the code
you just executed, rather than by hand!

7. Now it’s time to play. Try entering these commands, one at a time
(pressing Return after each one), and observing the results:

‣ Change the shape: g1.shape = "Circle"

‣ Change the stroke thickness: g1.strokeThickness = 12

‣ Change the fill: g1.fillColor = Color.RGB(1, 0, 0, 1)

‣ Change the stroke color: g1.strokeColor = Color.blue

The end result should look something like Figure 83. You can, of
course, play with any attributes you like—and follow similar steps to
discover how to draw other objects.

257
Figure 83: Your final shape after altering it with JavaScript.

258
Use a Macro Utility
Earlier in this book, I discussed Shortcuts, Automator, and Apple-
Script, three tools that can control numerous other apps and tie multi-
ple actions together into easy-t0-run shortcuts. All those technologies
are powerful, free, and included with macOS.
But AppleScript’s learning curve precludes casual use, while it’s limited
by the capabilities various apps choose to expose. Automator and
Shortcuts are far easier for a beginner to use, but they, too, have fairly
constrained palettes of capabilities—and not all the tasks you might
wish to automate fit their “workflow” mold. Meanwhile, apps like Excel
and Nisus Writer Pro have fantastic automation capabilities built in,
but they’re largely confined to activities within those apps.
So we come to a category of automation tools that—at the risk of
overstating my case—transcends these limitations. If you just want to
get the job done—not necessarily in the most programmatically elegant
way but in a fast, reliable, and flexible way—you want a macro utility.
It’s the sort of tool I reach for most often for general-purpose au-
tomation tasks.
Like other kinds of tools covered in this book, the idea of a macro
utility is straightforward. You pick an action, or a series of actions,
from a list; these form the macro’s task. Then you pick one or more
events to trigger that action—a keyboard shortcut, a button click, a
change in network settings, or whatnot. That’s it: you have a macro.

What’s interesting about the utilities discussed in this chapter is that


the lists of potential actions they offer as building blocks for macros
are long and diverse. Some of these actions, similar to AppleScript
verbs and Automator actions, directly control a particular app (Music,
Safari, the Finder) or send instructions to macOS (shut down, change
display brightness, switch users). Others manipulate behind-the-
scenes resources (clipboards, variables, strings) or manage the flow of
steps (if/then/else conditionals, loops, subroutines). Still others “play”

259
the visible interface, simulating button presses, menu commands,
keystrokes, and mouse movements.
Put all this together and you have a toolkit that—with a bit of clever-
ness and patient testing—can automate almost any repetitive Mac task
that doesn’t require creativity or human intuition. Here are just a
handful of examples, all of which can be done with a single click or
keystroke:

• Remap keys on your keyboard to perform different functions

• Show the screen of a shared Mac

• Force a “stuck” Trash to empty

• Add keyboard shortcuts to menu commands in apps that don’t


support the Mac’s built-in shortcuts

• Create an ad hoc Wi-Fi network

• Open an entire set of apps and documents

• Resize and reposition all your windows so they don’t overlap

• Modify text or formatting according to predefined patterns

• Email the URL of the web page you’re currently viewing to someone
else

• Rotate, flip, resize, or crop all the images in a folder

Having sung the praises of macro utilities generally, I must level with
you. For all practical purposes, we’re talking about one utility: Key-
board Maestro. Sure, I’ll mention a few other apps—see Use Another
Macro Utility—and I noted earlier that BetterTouchTool has macro-
like capabilities (see Use BetterTouchTool). Those other apps definitely
have their place, but if you want a great macro utility for your Mac,
Keyboard Maestro is (in my professional opinion) the best option by
far.

260
Control Your Mac with Keyboard Maestro
I’ve already given you a taste of what Keyboard Maestro can do, so let
me show you what it looks like, walk you through creating a couple of
macros, and explore some of its options and little-known features.

Create a Macro
When you open the Keyboard Maestro (Figure 84), you’ll see a three-
pane Editor interface. On the left is a list of groups, which you can use
to organize your macros however you like; this includes the All Macros
smart group. In the middle is the list of all the macros in the current
group. And on the right is the contents of the currently selected macro
(or a blank shell of a macro, if you’ve just created it). To create an
empty macro, click the plus button at the bottom of the Macros list.

Figure 84: The Keyboard Maestro editor with a new, blank macro
ready to be customized.

Within the macro pane (Figure 85), you see two areas: the trigger(s)
(top) and the action(s) (bottom). You can configure these two items in
any order. A trigger is what you do to make the macro run—a key-
stroke, a menu command, or a system event, say. (More about triggers
in a moment.) The action(s) are what happen when the trigger occurs.

261
Figure 85: The macro pane includes trigger and action areas.

Note: The icons that appear next to macro names may differ from
what you see here, but that’s irrelevant—they’re just for decoration.

Let’s walk through a few macros to see how it’s all done.

Macro #1: Open Login Items


For the sake of illustration, we’ll start by making a macro with a single,
simple trigger and a sequence of three actions. When you run this
macro, it displays System Settings > General > Login Items (Ventura
or later) or System Preferences > Users & Groups > Login Items
(Monterey or earlier). Ordinarily, you’d have to open System Settings/
System Preferences and then navigate to Login Items. So, we’re replac-
ing two or three clicks with one keyboard shortcut.)

Follow these steps:

1. If you haven’t already done so, launch Keyboard Maestro, select a


group (doesn’t matter which one), and click the plus button at
the bottom of the Macros list to create a new, blank macro.

2. Give your macro a name—replace Untitled Macro at the top with


Open Login Items.

3. Click New Trigger to display a pop-up menu from which you can
choose any of 20 trigger types. Choose Hot Key Trigger (the first
item) from this menu to use a keyboard shortcut as the trigger.

262
4. You’ll notice that the Type field under the text “This hot key” is
already selected. So press the keyboard shortcut you want to use to
trigger this macro. It can be anything you like, but I suggest choos-
ing something obscure that isn’t already being used for something
else, like ⌘-Option-Control-L.

Note: A macro can have more than one trigger, and you can change
your trigger(s) at any time.

5. Click New Action to display a new pane (which covers the two left-
most columns of the window) with a list of all possible actions,
grouped by category (Figure 86).

Figure 86: Keyboard Maestro’s actions are grouped by category.

263
From here, the instructions diverge depending on which version of
macOS you’re running.

In Ventura or later:
6. The first action is to open the System Settings app.

To do this, click Application Control in the Categories list and then


drag Activate a Specific Application to the “No Action” label on the
right (or just double-click the action). Then choose System Settings
from the Activate pop-up menu.

7. When you launch System Settings, it may take a moment to open.


That could break the macro if there’s no delay, as we want to wait
until it’s open to switch to the Login Items view.

To solve this problem, drag the Pause Until action (from the Control
Flow category) underneath the Activate System Settings action.
Click New Condition and choose Front Window Condition from the
pop-up menu. Then, from the Front Application pop-up menu,
choose System Settings (if it’s not already there, click More at the
bottom to expand the list). Leave the last pop-up menu set to Exists.

8. Now we need to switch to the Login Items view. Click Interface


Control in the Categories list, and add the Select or Show a Menu
Item action to the end of your action list. From the “Select menu in”
pop-up menu, choose System Settings. Then type View into the
Menu Title field and Login Items into the Menu Item field. At this
point, the macro should look like Figure 89.

264
Figure 87: The final Open Login Items macro for Ventura or later, in
edit mode.

9. Click the Edit button at the bottom to deselect it. (The macro will
work fine even if you don’t leave edit mode, but doing so keeps you
from making accidental changes to your macro.) Once you’re no
longer in edit mode, the macro should look like Figure 88.

265
Figure 88: The final Open Login Items macro for Ventura or later.

Now skip ahead to Run the macro.

In Monterey or earlier:
6. The first action is to open the User & Groups pane of System
Preferences.

To do this, click Open in the Categories list and then drag Open a
System Preference Pane to the “No Action” label on the right (or
just double-click the action). If Users & Groups isn’t already shown
next to “Open preference pane,” choose it from the pop-up menu.

7. When you launch System Preferences, it may take a moment to open,


and we want to wait until then to switch to the Login Items view to
avoid breaking the macro.

So, drag the Pause Until action (from the Control Flow category)
underneath the Open Users & Groups Preference Pane action. Click
New Condition and choose Front Window Condition from the pop-
up menu. Then, from the Front Application pop-up menu, choose
System Preferences (if it’s not already there, click More at the
bottom to expand the list). Leave the last pop-up menu set to Exists.

266
8. Now we need to switch to the Login Items view (in case that’s not
what the window is currently set to).

Click Interface Control in the Categories list, and add the Press a
Button action to the end of your action list. Replace the text OK with
Login Items. At this point, the macro should look like Figure 89.

Figure 89: The final Open Login Items macro for Monterey or
earlier, in edit mode.

267
9. Click the Edit button at the bottom to deselect it. (The macro will
work fine even if you don’t leave edit mode, but doing so keeps you
from making accidental changes to your macro.) Once you’re no
longer in edit mode, the macro should look like Figure 90.

Figure 90: The final Open Login Items macro for Monterey or earlier.

Run the macro:


We’re ready to rock! Press ⌘-Option-Control-L (or whichever combi-
nation you chose). System Settings/System Preferences should open to
the Login Items view of General/Users & Groups.

Tip: If a Keyboard Maestro macro appears not to work at all, try


choosing File > Quit Engine to quit the Keyboard Maestro Engine.
Wait a moment, and then choose File > Launch Engine to restart it.

Macro #2: Convert Formats


Your favorite word processor can probably import and export files in
various text formats. But macOS also includes a command-line utility
called textutil that can convert files to or from any of nine different
formats, among its other talents. Want to go from Word (.doc or .docx)
to HTML (or vice versa)? You can do that with a Keyboard Maestro
macro that employs a shell script, and never launch Word at all.

268
Note: I abbreviate most of the following steps; for more details refer
to the instructions for the previous example.

Follow these steps:

1. As in Macro #1: Open Login Items, create a new macro. Name it


Convert Format.

2. Click New Trigger to display a pop-up menu of trigger types. Choose


Status Menu Trigger (just for variety).

3. Add your first action—Prompt for User Input (in the Variables
category)—which will prompt you, the user, to choose a destination
file format.

4. Fill in Convert Format for the Title, and in the Prompt field, type
Choose the format you want to convert the selected file(s) to.
Must be one of: txt, html, rtf, rtfd, doc, docx, wordml, odt,
webarchive.

5. Click the plus button under Variables and Default Values to add
a new variable. Enter To in the first field (the variable’s name) and
html in the second field (its default value).

6. Next, tell the macro that it should operate on whichever file(s) you
happen to have selected in the Finder: add the For Each action (in
the Control Flow category) to the end of your action list. Replace the
text Variable in the For Each field with filePath. Click the plus
button next to New Collection, and choose Finder’s Selection Collec-
tion from the pop-up menu.

7. Finally, it’s time to add the shell script. But it’s not an independent
action; rather, it’s part of the For Each action—that is, the shell
script will run on each item you selected in the Finder. Add an
Execute a Shell Script (from the Execute category) into the No
Action area (surrounded by a dotted line) at the bottom of the For
Each action. In the field that appears there, type this:

textutil -convert $KMVAR_To -strip "$KMVAR_filePath"

At this point, your macro should look like Figure 91.

269
Figure 91: The final Convert Format macro, in edit mode.

270
8. Optional but recommended: click the Edit button at the bottom to
deselect it.

Now you can run the macro, but first you’ll need at least one document
somewhere in one of the supported formats (from step 6 above). I
suggest copying one or more such files to your Desktop to make them
easier to work with.

One last thing before we run the macro: if Keyboard Maestro’s status
or menu isn’t visible in your Mac’s menu bar, switch back to
Keyboard Maestro, go to Keyboard Maestro > Settings/Preferences >
General and make sure Display Status Menu is set to either Alphabeti-
cally, By Group, or Hierarchically (i.e., not Never).

Now select the file(s) you want to convert. Then, choose Convert
Format from the Keyboard Maestro status or menu. You should
see the dialog (which you created!) (Figure 92).

Figure 92: This dialog should appear when you run your macro.

Leave the To field set to its default, and click OK. A new file should
appear with the same name and location as the old file (which will still
be there) but with the .html extension—and it’ll be in HTML format!
(Feel free to run the macro as often as you like, with different To
settings and different files selected to see how it works.)

Macro #3: Convert to Title Case


Here’s a goofy little macro that few people would be likely to use in
exactly its current form, but it illustrates a few useful Keyboard Mae-
stro features, and you can certainly adapt it to your own needs. When

271
it runs, it selects all the text on the current line up to and including the
insertion point and converts that text to title case (like the heading just
above this paragraph). But the trigger is just typing a few characters.

Follow these steps (refer to Macro #1: Open Login Items for details):

1. Create a new macro and name it Convert to Title Case.

2. Click New Trigger to display a pop-up menu of trigger types. Choose


Typed String Trigger. Then type cttc in the This String is Typed
field, with the surrounding pop-up menus set to “case must match,”
“match after any character,” and “diacriticals matter.” Also select
the “Simulate 4 deletes before executing” checkbox.

3. The first action simulates the keystrokes needed to select text from
the insertion point back to the beginning of the line. To do this, add
the Type a Keystroke action (from the Interface Control category).
Then click in the Simulate Keystroke field and type ⌘-Shift-←.

4. Next, we want the macro to pause for half a second, to allow that
action time to complete. To do this, add a Pause action (from the
Control Flow category). Fill 0.5 in the blank.

5. Now we want to copy the selected text to a special clipboard (so that
the main clipboard isn’t overwritten). To do this, add a Copy to
Named Clipboard action (from the Clipboard category). From the
second pop-up menu, choose New. Type the name Title Case, and
close the window. Title Case should then automatically be selected
in that pop-up menu.

6. We’ll use one of Keyboard Maestro’s predefined text filters to


change the contents of our Title Case clipboard. Add a Filter Clip-
board action (from the Clipboard category) to the macro. Choose
Title Case from the Filter pop-up menu, and then choose Title Case
again from the “with” pop-up menu.

7. Finally, we paste the revised clipboard, overwriting what we select-


ed earlier. Add the action Paste from Named Clipboard (from the
Clipboard category) and choose Title Case from the second pop-up
menu.

272
Your macro should now look like Figure 93. (I’ll skip the step of
turning off edit mode and showing you what that version looks like,
although you can do that if you like.)

Figure 93: The Convert to Title Case macro.

To run this macro, make sure your insertion point is at the end of a
line. Then type cttc (without any modifiers). The macro runs, and your
trigger characters disappear.

273
Macro #4: Paste Previous Clipboard
I told you Keyboard Maestro includes a clipboard history. One of my
favorite ways to use this is to press a keystroke that pastes whatever
was on my clipboard just before the current thing. So, if I copy and
paste something, copy a second thing, but then want to paste the first
thing again, this is what I use.

Follow these steps, again using earlier instructions as a guide:

1. Create a new macro and name it Paste Previous Clipboard.

2. Assign the macro a hot key trigger of ⌘-Control-V (or whatever you
like).

3. Add two actions: Set Clipboard to Past Clipboard (from the Clip-
board category), with System Clipboard chosen from the Set menu
and 1 entered as the number of the clipboard; and Type a Keystroke
(from the Text category), with ⌘-V entered as the keystroke. The
result should look like Figure 94.

Figure 94: The Paste Previous Clipboard macro.

274
With this macro enabled, simply press ⌘-Control-V to paste the
previous contents of the clipboard.

Record a Macro
If you read Automate Microsoft Office, you may recall that in Office
apps, you can record a macro. In other words, Office will watch you
while you perform activities, and then make them into a macro. You
can play this macro back later, no coding required. Keyboard Maestro
offers a similar feature. It won’t always produce results as reliable as
those you get creating your own macro from scratch—and not every
kind of macro can be recorded—but it’s a simple way to ease into
macro construction or get unstuck if you’re stuck.

To record a macro:

1. Create a new macro, just as in the earlier examples, and give it a


name and trigger.

2. Instead of filling in actions, click the Record button at the very


bottom of the window. A little 5-second countdown timer appears
on screen (Figure 95).

Figure 95: This floating window appears when you record a macro.
The countdown timer (left) gives way to the icon on right when it
reaches zero.

3. Once the timer has counted down to zero and the icon says Record-
ing, do stuff. Whatever you like. Switch apps, type some text, apply
formatting, choose menu commands, click buttons, anything. You
know, stuff.

4. Click the floating Recording icon to stop recording and examine


your new macro in Keyboard Maestro.

275
5. Optional but recommended: click Edit to leave edit mode.

Now try running your macro. If the macro doesn’t work as expected—
which is likely—go back and click Edit to return to edit mode and see if
you can modify some of the actions to do what you want them to do.
You may also need to add Pause or Pause Until actions to force the
macro to wait for your Mac to catch up with it at certain points.

Learn About Keyboard Maestro Actions


I’ve shown you a handful of actions in the course of walking you
through the sample macros. There are many, many more of them. You
can learn about actions by looking at the Keyboard Maestro documen-
tation, or by trying them out. Here are just a few actions and categories
that I find particularly interesting:

• Activate Clipboard History Switcher (Switchers category):


I mentioned in Use a Macro or Launcher Utility that Keyboard
Maestro is also an excellent clipboard utility, with its own clipboard
history. This action displays a floating window with that history.

• Filter Clipboard (Clipboard category): Speaking of clipboards,


this action can make a wide variety of changes to the contents of
your clipboard. Use it to remove styles, change case, perform a
calculation, count words, and more.

• Google Chrome Control category, Safari Control category:


Thanks to the actions in these categories, you can automate nearly
anything in Google Chrome or Safari. Open a webpage, fill in and
submit a form, click buttons, create new tabs, execute JavaScripts,
and perform other activities.

• Execute category: If your macro needs capabilities that Keyboard


Maestro’s built-in actions don’t provide, you can use the actions in
this category to run a shell script (as we did in Macro #2: Convert
Formats), an AppleScript, JavaScript, Swift script, or Automator
workflow as part of your macro. (You can also apply a BBEdit text
factory—look in the Clipboard category.)

276
• Find Image on Screen (Image category): This blew my mind
when I first saw it. Keyboard Maestro can identify an area on your
screen matching an image (perhaps a cropped screenshot) that you
supply, and having found that portion of your screen, it can high-
light it, move the mouse to it, or take other actions.

Alternatively, a macro can choose to do something or not based on


whether an arbitrary portion of your screen matches an image. As
just one example of why this is interesting, a blind reader wrote to
tell me he uses this feature, in conjunction with AppleScript, to
speak the status of an icon on his screen (enabled or disabled) that
he’d have no other way to determine because it’s unavailable to
VoiceOver. I think that’s amazing. To learn more about using this
action, read How to Assign a Hotkey to Almost Anything by Patrick
Welker.

Tip: Keyboard Maestro itself is VoiceOver-accessible, which opens its


capabilities to those with limited sight. For instance, you can also use
Keyboard Maestro’s Speak Text macro to create macros that deliver
status reports verbally.

• Variables category: We used two variables in Macro #2: Convert


Formats—one of which passed the contents of a field in a dialog to a
shell script and the other of which contained the path of each file
being operated on. There are countless other ways to use variables,
but what I find most valuable is that they’re able to take information
created or discovered by one action and reuse it in another action
that comes later in the macro.

• Control Flow category: Keyboard Maestro offers extensive tools


for adding logic to your macros. This category contains several
kinds of loops, an “If Then Else” structure for taking your macro in
different directions depending on conditions you specify, various
ways to pause a macro, options to run subroutines (or call other
macros), and quite a few other options.

277
Learn About Keyboard Maestro Triggers
Just as Keyboard Maestro has lots of nifty actions, it has a crazy array
of triggers. We’ve seen keyboard shortcuts and commands on the
Keyboard Maestro status menu, but there are 29 other options too. I’m
not going to enumerate all of them here—you can read all about them
in the Keyboard Maestro documentation—but I want to call out a few
that I think are especially noteworthy:

• Typed String Trigger: Unlike a keyboard shortcut, which uses a


combination of keys pressed at once (typically with modifiers such
as Command, Control, Option, and/or Shift), a typed string trigger
is a sequence of keys you type without a modifier. In Automate Text
Expansion, we saw how software can turn a typed abbreviation into
a longer chunk of text. This is the same idea, except that typing an
abbreviation runs a macro (and optionally deletes the characters
you just typed)—just as we did in Macro #3: Convert to Title Case.
For another example, I could type an abbreviation that fills in some
predefined text, selects the entire current paragraph, and copies it
to the clipboard—all in one operation.

• Time Trigger: Have your macro run on a timer! This trigger lets
you select the time and day(s) of the week you want it to run.

• MIDI Trigger: If you have a piano-style MIDI keyboard (or any


other MIDI instrument) connected to your Mac, you can trigger a
Keyboard Maestro macro when you play a particular note. (Inciden-
tally, there are also MIDI actions to send note on, note off, and
control change messages.)

• Macro Palette Trigger: This floating palette normally takes the


form of a small icon (which you can position anywhere on your
screen). Mouse over it and it displays a list of macros that you can
trigger with a single click (Figure 96).

278
Figure 96: The macro palette is normally unobtrusive (left), but
when you mouse over it, it expands to show macros you can activate
with a click.

• Wireless Network Trigger: You can trigger a macro by connect-


ing to, or disconnecting from, a certain Wi-Fi network.

• Focused Window Trigger: When the window that currently has


focus (that is, the frontmost window) changes, or when its title or
frame change, a macro can run automatically.

• URL Trigger: You can click a specially formatted URL in another


app to trigger a macro.

Use Another Macro Utility


Even though Keyboard Maestro is an excellent macro utility for mac-
OS, it’s not the only one. Because I know people will ask, I do want to
say a few words about other Mac macro utilities:

• Alfred: Alfred, which I discussed in Use a Third-Party Launcher, has


a feature called workflows that’s available only if you purchase the
optional Powerpack. Workflows connect a trigger (such as pressing
Alfred’s hot key and typing an abbreviation) and/or one or more
inputs (such as keyword or filters) with one or more actions (such as
opening a file or URL, or running a shell script or AppleScript) and
optional outputs (such as a notification or putting something on the
clipboard). So an Alfred workflow is certainly a variety of macro, but
it’s more limited in its triggers, actions, and logic than what you’ll
get in Keyboard Maestro, while being (in my opinion) harder to
understand than an Automator workflow.

279
That’s not to say Alfred workflows aren’t extremely useful—they are.
With a few keystrokes in Alfred, you can create a new note or search
in Evernote, perform a search on multiple websites at once, or open
a selected image in a browser instead of Preview. But they require a
particular way of thinking about tasks that doesn’t match the way
my brain works, so I find it difficult to recommend them.

• BetterTouchTool: As I mentioned in Use BetterTouchTool, this


utility, ostensibly for customizing input devices, can also create
sequences of actions that function like full-blown macros. Note that
it lacks the depth and the flow control tools of Keyboard Maestro.

• yKey: Although not in the same league as Keyboard Maestro, yKey


(formerly called iKey) is a fine little macro utility. It has a reason-
ably thorough list of triggers and actions, and can dispatch many
repetitive tasks with ease.

yKey doesn’t include logic, as such. For example, it can wait for
certain app or window states before moving on with the next step in
a macro, but it can’t make if/then/else decisions, process variables,
perform loops, search for text patterns, or evaluate complex condi-
tions as Keyboard Maestro can. And its interface is odd—it strikes
me as being backward from the way most macro utilities approach
triggers and actions. Finally, and most seriously, it hasn’t yet been
updated to support Monterey, so its future seems iffy.

Farewell, ControlPlane
At this point in earlier versions of the book, I covered a wonderful
utility called ControlPlane, which used settings or situations known as
contexts to trigger various types of automations.
For example, I could configure it to launch a certain app whenever I
connected my MacBook Pro to AC power, and quit that whenever I
unplugged my Mac. It could rearrange my windows in a particular
way when I connected a second display, and it could switch my Mac’s
audio input whenever I plugged in external speakers.
Unfortunately, at some point since the previous version of this book,
the ControlPlane website went offline, and as far as I can tell, the app
has been discontinued.

280
About This Book
Thank you for purchasing this Take Control book. We hope you find it
both useful and enjoyable to read. We welcome your comments.

Ebook Extras
You can access extras related to this ebook on the web. Once you’re on
the ebook’s Take Control Extras page, you can:

• Download any available new version of the ebook for free, or buy a
subsequent edition at a discount.

• Access the book in both PDF and EPUB formats. (Learn about
reading on mobile devices on our Device Advice page.)

• Read postings to the ebook’s blog. These may include new informa-
tion and tips, as well as links to author interviews. At the top of the
blog, you can also see any update plans for the ebook.

If you bought this ebook from the Take Control website, it has been
automatically added to your account, where you can download it in
other formats and access any future updates.

More Take Control Books


This is but one of many Take Control titles! We have books that cover
a wide range of technology topics, with extra emphasis on Macs and
other Apple products.
You can buy Take Control books from the Take Control online catalog
as well as from venues such as Amazon and the Apple Books Store.
But it’s a better user experience and our authors earn more when you
buy directly from us. Just saying…
Our ebooks are available in two formats, PDF and EPUB, which are
viewable on any computer, smartphone, tablet, or e-reader. All are
DRM-free.

281
About the Author and Publisher

Joe Kissell is the author of more than 60 books and hundreds of


articles about technology. In 2017, he also became the publisher of
Take Control Books, when alt concepts—the company he runs along
with his wife, Morgen Jahnke—acquired the Take Control series from
TidBITS Publishing Inc.’s owners, Adam and Tonya Engst. Before he
began writing full-time in 2003, Joe managed software development
for a living. He holds a bachelor’s degree in Philosophy and a master’s
degree in Linguistics.

In his hypothetical spare time, Joe likes to travel, walk, cook, eat, and
practice t’ai chi. He lives in Saskatoon, Saskatchewan, Canada, with
Morgen, their sons, and their cat. To contact Joe about this book, send
him email and please include Take Control of Automating Your Mac in
the subject. You can also sign up for joeMail, his low-volume mailing
list, visit his blog at JoeKissell.com, or follow him on Mastodon
(@joekissell).

Acknowledgments
Bill Cheeseman and Sal Soghoian offered invaluable input and sug-
gestions for an earlier edition of this book. I also appreciated the
helpful feedback of all the technical reviewers of the first edition—
especially Peter N Lewis and Greg Scown. And I’m grateful to all the

282
developers who generously provided the coupons at the end of this
book. Thank you!

Credits
• Publisher: Joe Kissell
• Editor: Glenn Fleishman
• Cover design: Sam Schick of Neversink
• Logo design: Geoff Allen of FUN is OK

283
Copyright and Fine Print
Take Control of Automating Your Mac, Fifth Edition
ISBN: 978-1-990783-47-0
Copyright © 2024, Joe Kissell. All rights reserved.
alt concepts, 419 8B-3110 8th St. East, Saskatoon, SK S7H 0W2 Canada

Why Take Control? We designed Take Control electronic books to help readers regain
a measure of control in an oftentimes out-of-control universe. With Take Control, we also
work to streamline the publication process so that information about quickly changing
technical topics can be published while it’s still relevant and accurate.
Our books are DRM-free: This ebook doesn’t use digital rights management in any
way because DRM makes life harder for everyone. So we ask a favor of our readers. If you
want to share your copy of this ebook with a friend, please do so as you would a physical
book, meaning that if your friend uses it regularly, they should buy a copy. Your support
makes it possible for future Take Control ebooks to hit the internet long before you’d find
the same information in a printed book. Plus, if you buy the ebook, you’re entitled to any
free updates that become available.
Remember the trees! You have our permission to make a single print copy of this
ebook for personal use, if you must. Please reference this page if a print service refuses to
print the ebook for copyright reasons.
Caveat lector: Although the author and alt concepts have made a reasonable effort to
ensure the accuracy of the information herein, they assume no responsibility for errors or
omissions. The information in this book is distributed “As Is,” without warranty of any
kind. Neither alt concepts nor the author shall be liable to any person or entity for any
special, indirect, incidental, or consequential damages, including without limitation lost
revenues or lost profits, that may result (or that are alleged to result) from the use of these
materials. In other words, use this information at your own risk.
It’s just a name: Many of the designations in this ebook used to distinguish products
and services are claimed as trademarks or service marks. Any trademarks, service marks,
product names, or named features that appear in this title are assumed to be the property
of their respective owners. All product names and services are used in an editorial fashion
only, with no intention of infringement. No such use, or the use of any trade name, is
meant to convey endorsement or other affiliation with this title.
We aren’t Apple: This title is an independent publication and has not been authorized,
sponsored, or otherwise approved by Apple Inc. Because of the nature of this title, it uses
terms that are registered trademarks or service marks of Apple Inc. If you’re into that sort
of thing, you can view a complete list of Apple Inc.’s registered trademarks and service
marks.

284
Also by Joe Kissell
Click any book title below or visit our web catalog to add more ebooks
to your Take Control collection!

Take Control of 1Password: Slowed down by entering passwords


repeatedly? Learn how to let 1Password do the heavy lifting.

Take Control of Apple Mail: Learn the ins and outs of Apple’s email
app in macOS and iOS.
Take Control of Backing Up Your Mac: Protect your Mac’s valuable
data from any sort of mishap.
Take Control of DEVONthink 3: Master this powerful information
management tool.

Take Control of iCloud: Understand the many features, get set up


properly, and enjoy iCloud!

Take Control of Ventura: Discover what’s new in macOS 13 and get all
the information you need to upgrade safely.
Take Control of the Mac Command Line with Terminal: Master your
Mac’s command-line interface and learn basic Unix skills.

Take Control of Your Digital Legacy: Make sure your important


digital information is preserved for future generations.

Take Control of Your Online Privacy: Learn what’s private online (not
much)—and what to do about it.

Take Control of Your Paperless Office: With your Mac, scanner, and
this ebook in hand, you’ll finally clear the chaos of an office overflow-
ing with paper.

Take Control of Your Passwords: Overcome password overload


without losing your cool—and view the comic that goes with this
ebook!

285
Hazel Coupon
To save 20% on Hazel, visit the Noodlesoft Store page to see the
discount pricing, enter how many copies you want, and check out.

286
Keyboard Maestro Coupon
To save 20%, visit the Keyboard Maestro website and be sure to input
the coupon code TCOAYM as you check out.

287
LaunchBar Coupon
To save 20%, go the Objective Development Shop page, add Launch-
Bar to the cart, and enter DT-4460-7113 in the Discounts field.

288
Nisus Writer Pro Coupon
To save 25% on Nisus Writer Pro, visit the Nisus Software Take Con-
trol Readers page and click the appropriate Buy button.

289
Script Debugger Coupon
To save 15% on Script Debugger, use this URL to automatically apply
discount code TAKECONTROL17.

290
TypeIt4Me Coupon
To save 30% on TypeIt4Me, visit the Ettore Software coupon page and
click Buy Now.

291
Typinator Coupon
To save 30%, go to the Ergonis Store page, add Typinator to your cart,
and enter coupon code TCO-TYPINATOR.

292

You might also like