Since the other answer is a bit devoid of explicit/specific details, this is meant to show how it can be done.
/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
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.
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.
sudo nano com.my.MountTimeMachineSparseBundle.plist
- Copy and paste the example PLIST XML code into
nano, save it (^O Enter), and exit
<?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">
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.