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.
#!/bin/bash
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"
fi
fi
- 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">
<dict>
<key>Label</key>
<string>com.my.MountTimeMachineSparseBundle </string>
<key>ProgramArguments</key>
<array>
<string>/Users/Shared/bin/MountTimeMachineSparseBundle</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>StartOnMount</key>
<true/>
</dict>
</plist>
Then:
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.
fstab
entry and actual real world pathnames/filenames germane to the issue.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 currenthdiutil
command isn't valid as having\040
inCloud\040Folder
will returnhdiutil: attach failed - No such file or directory
.