Automatically Mount External Drive to Clone a Mac

Simple Mac Automator Example

I know some people find automation daunting. Fortunately, some of the most effective Mac automations are simple enough to get anybody started. The native MacOS automator app alone can save you from boring and repetitive tasks. Better still, Mac automation can save you from having to remember those tasks. A good example of a simple automation is how to automatically mount an external drive to create a bootable clone for backup.

Backup Strategies for macOS

The past 18 months we’ve had some hardware failures that took me from feeling over-prepared to being relieved I have this all set up. A solid backup and recovery scheme is table stakes for most nerds, but in my experience the same can’t be said of academics. To say nothing of the way most students wing it with their data. I’ve lost count of the horror stories I’m privy to. Undergrads losing devices, or having them pinched. Graduate students having to ask supervisors for a copy of their own thesis, or recompile dissertations from draft fragments. My backup strategy looks like this:

  1. Regular time machine backups to an external drive on my Synology rt2600ac router. Setting up Time Machine to backup wirelessly is an overlooked example of Mac automation
  2. Continuous offsite backup of everything to Backblaze. For US$5 a month, I have almost 6 terabytes of files backed up.
  3. An automated, bootable clone of my entire system updated every night using SuperDuper!

If you have a solid backup strategy, regularly creating bootable clones of your whole system drive is no doubt part of it. If it isn’t, it should be.

Automatically Mounting an External Hard Drive

One of the problems with automating the creation of a bootable clone is the drive must be mounted. That might seem like I’m stating the bleeding obvious, or overlooking an obvious solution, but keeping a clone of your system mounted at all times can create all kinds of problems. Once the drive is indexed, you can have issues with document conflicts, messed up caching, and all manner of application weirdness. It doesn’t take much to launch the wrong version of an app, then you’re in a world of hurt.

The answer, of course, is to automatically mount the drive before backup, and eject it afterwards. But how to do that? Ejecting the drive is the easy part. Any decent backup, cloning app will have this functionality. This includes apps like Chronosync, Carbon Copy Cloner, or if you’re a Setapp user, Backup Pro. My favourite drive cloning software for Mac is Super Duper! for its elegant simplicity. Using Super Duper! to automatically eject the drive looks like this:

Automatically Mount External Drive
Any decent macOS backup utility will have the ability to automatically eject an external drive aftre creating a bootable clone

But, we are putting the cart in front of the horse. The question remains, how to automatically mount the drive. Thankfully, that is also simple. We can use a single command in AppleScript.

One Line AppleScript  to Automatically Mount External Drive

A simple one line AppleScript to make a Mac automatically mount an external drive looks like this:

do shell script "diskutil mount clone"

To make it work you either name your drive ‘clone, or edit the script where it says ’clone’ with the name of the target volume. All that’s left is how to trigger the script. The more you start to peel back the layers on Mac automation, the more you realise how many different options there are. Here are three ways to run the above AppleScript, and automate the mounting of an external drive.

Automatically Mount External Drive with Automator Calendar Alarm

 

The first option is to use Automator, the native Mac app. Automator can utilise the Mac Calendar app to trigger simple MacOS automations with an alarm. Here's how to setup an Automator Calendar Alarm.

  1. Open Automator from your applications
  2. Choose Calendar Alarm
  3. Search the actions on the left for ‘Run AppleScript’ and drag that action across to the workflow editor on the right — or double click
  4. Clear the window and past our single line of AppleScript into the ‘Run AppleScript’ window. Here is that line of code again:

do shell script "diskutil mount clone"

Simple macOS automation using one line of AppleScript
  1. Click on the little hammer icon to compile the script, then save the workflow and give it a name.
  2. As soon as you save the workflow it will open the calendar app with a new entry. All you need to do is move it, and schedule it like you would any other event.
Automatically Mount External Drive
Automator can trigger an alarm in the native Calendar App to automatically mount an external drive
  1. You’re done, have yourself a Pixie Caramel

There is amore convoluted way to do this from the calendar itself, but the result is the same. I recommend building the workflow yourself, simple as it is. But if you’d rather, you can download a copy here

Automatically Mount External Drive with Keyboard Maestro

I would be happy using the Automator workflow above if I didn’t already use Keyboard Maestro. Setting up Keyboard Maestro to trigger the script is easier still. It’s not the kind of thing I suggest you purchase the app for, but the kind of simple use case it is often overlooked for.

 

Keyboard Maestro Macro

Automate AppleScript Launch with Lingon X

Another option is to use Lingon X, a powerful automation utility that can launch practically anything. Lingon X is ideal for a job like this. To use Lingon you ned to save the script itself first.

  1. Launch the native Mac Script Editor from Utiities
  2. Paste the AppleScript into the editor do shell script "diskutil mount clone"
  3. Compile with the little hammer
  4. Save the script
  5. Schedule a new job in Lingon X to run the script before your clone is set to run.
simple macOS automation
Lingon X is a powerful utility for creating simple macOS automation

There is also an App Store version for Lingon available.

Choosing an External Hard Drive for Bootable Clone

The last word on this is doubled edged. You should of course try to be savvy about the external hard drives you buy, but this workflow wouldn’t exist if you could be certain you’ll never buy a lemon. I mentioned in my post on replacing the Apple Airport Extreme that Backblaze keep excellent drive statistics. Understandably, it doesn’t include the kind of portable external hard drives you will likely use for this kind of automated clone backup. I feel well covered with my setup, but I know plenty of people who like to rotate the drives and keep one offsite. Either way, I have always found Seagate Expansion drives to be fast, and reliable. Connected to a Hub, and stashed under the desk to avoid more clutter.