I have one external SSD drive that automatically mounts a partition Backup. Inside Backup there is a sparse-bundle disk image called TimeMachine.

Backup is not mounted to /Volume but to a specific folder (synced with a cloud service), via /etc/fstab:

UUID=4E5D0103-741G-46DA-A79E-F923E5C951D1 /Users/myuser/Cloud\040Folder/Backup apfs rw 0 2

How can I trigger the automatic mount of TimeMachine, when detecting that Backup has been mounted?

Something like hdiutil attach /Users/myuser/Cloud\040Folder/Backup/TimeMachine.sparsebundle, being run when detecting that /Users/myuser/Cloud\040Folder/Backup is present.

Maybe the /etc/auto_master file might help? (I've never used it before)

  • Please edit your question and provide the relevant fstab entry and actual real world pathnames/filenames germane to the issue. – user3439894 Apr 9 '20 at 19:58
  • Originally, before my first comment, you had the hdiutil command using the -mountpoint option, i.e. hdiutil attach /Volume/A/B.dmg -mountpoint ~/myMountedB -- Are you no longer using the -mountpoint option? If you are, please edit the question with the missing information. Also, your current hdiutil command isn't valid as having \040 in Cloud\040Folder will return hdiutil: attach failed - No such file or directory. – user3439894 Apr 10 '20 at 22:51

You can create a launchd LaunchDaemon definition with the key “StartOnMount” set to true. This will allow you to have your own script run whenever something is mounted.

Your own script should then just check if “Backup” is mounted without “TimeMachine” being mounted - and if so, mount “TimeMachine”.

You can use the “mount” command to get information on the currently mounted file systems.


Since the other answer is a bit devoid of explicit/specific details, this is meant to show how it can be done.

In /etc/fstab I've added the appropriate entry to have the target disk containing the TimeMachine.sparsebundle file automatically mount to the target location, when inserted, as shown in your post.

As it's not clear yet you are using the -mountpoint with hdiutil the following assumes your not, since you removed it, however I will update the bash code as necessary, if need be.

I have tested the following steps and code, and it works, to automatically have the TimeMachine.sparsebundle file mounted when the target disk containing it is mounted.

1. Create the bash script that will be executed whenever a disk is mounted.

  In Terminal:

cd /Users/Shared
mkdir bin
cd bin
touch MountTimeMachineSparseBundle
open -e MountTimeMachineSparseBundle
  • Copy and paste the example bash code into the opened document, replacing _you_ in the hdiutil command with your short user name, save and close.

if [ "Cloud Folder/Backup" == "$(mount | grep -o "Cloud Folder/Backup")" ]; then
    if [ "/Volumes/TimeMachine" !=  "$(mount | grep -o "/Volumes/TimeMachine")" ]; then
        hdiutil attach "/Users/_you_/Cloud Folder/Backup/TimeMachine.sparsebundle"
  • Back in Terminal, make the bash script executable:
chmod +x MountTimeMachineSparseBundle

2. Create the .plist file the daemon will use to execute the bash script used to automatically have the TimeMachine.sparsebundle file mounted when the target drive containing it is mounted.

  In Terminal:

cd /Library/LaunchDaemons
sudo nano com.my.MountTimeMachineSparseBundle.plist
  • Copy and paste the example PLIST XML code into nano, save it (^O Enter), and exit nano (^X).
<?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">
    <string>com.my.MountTimeMachineSparseBundle </string>


sudo chmod 0444 com.my.MountTimeMachineSparseBundle.plist
sudo launchctl load com.my.MountTimeMachineSparseBundle.plist

Now when the target disk containing the TimeMachine.sparsebundle file is mounted, the TimeMachine.sparsebundle file will also be mounted.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .