Automatically mount Sparsebundle?

Namtaro

macrumors regular
Original poster
Dec 4, 2011
135
0
Is there any way to do this?

I have a sparsebundle on a fileserver that I use for timemachine backups and everything's great... it's just that I have to manually mount it every time I wake the macbook from sleep.

I have tried dragging the sparsebundle into the login items, but that only mounts the shared harddrive and doesn't mount the sparsebundle itself.

Any solutions would be awesome, thanks!
 

Weaselboy

Moderator
Staff member
Jan 23, 2005
30,419
10,218
California
I think you could do it with the below shell script in an Applescript launched at login.

Code:
hdiutil attach -mountpoint ~/myMountPoint mySparsebundle.dmg
 

Namtaro

macrumors regular
Original poster
Dec 4, 2011
135
0
Sorry, I've never used Applescript before, any instructions to do so?
 

Weaselboy

Moderator
Staff member
Jan 23, 2005
30,419
10,218
California
Sorry, I've never used Applescript before, any instructions to do so?
Okay. Start the Applescript editor from /Applications/Utilities and paste in the text below. Change extDriveName to whatever your external drive is called. Also change mySparsebundle.dmg to whatever you sparsebundle is called. Now click Run to test. If it works okay, go ahead and save the Applescript wherever you want. Documents folder is fine. Now add the Applescript to your login items. That should do it.

Code:
do shell script "hdiutil attach -mountpoint /Volumes/[I]extDriveName[/I] [I]mySparsebundle.dmg[/I]"
 

Namtaro

macrumors regular
Original poster
Dec 4, 2011
135
0
Okay. Start the Applescript editor from /Applications/Utilities and paste in the text below. Change extDriveName to whatever your external drive is called. Also change mySparsebundle.dmg to whatever you sparsebundle is called. Now click Run to test. If it works okay, go ahead and save the Applescript wherever you want. Documents folder is fine. Now add the Applescript to your login items. That should do it.

Code:
do shell script "hdiutil attach -mountpoint /Volumes/[I]extDriveName[/I] [I]mySparsebundle.dmg[/I]"



do shell script "hdiutil attach -mountpoint /Volumes/Timemachine timemachine.sparsebundle"
That's what I've written so far and it's turning up an error
error "hdiutil: attach failed - No such file or directory" number 1
You said to change extDriveName to my external drive... but I do not have the sparsebundle on an external drive, but on a networked drive. That might be the problem?
 

Weaselboy

Moderator
Staff member
Jan 23, 2005
30,419
10,218
California
That's what I've written so far and it's turning up an error

You said to change extDriveName to my external drive... but I do not have the sparsebundle on an external drive, but on a networked drive. That might be the problem?
Oh yes... that changes things. Follow this to mount the NAS at login then use the Applescript to mount the sparse bundle.

Change the mountpoint /Volumes/extDriveName section to the NAS location. Look toward the bottom of the page I linked and you will also see a way to add the network mount to the Applescript.

It is hard for me to do this without knowing what protocol you are using to share. If you post up the NAS share location, I'll try and string it all together into one script for you.
 

Namtaro

macrumors regular
Original poster
Dec 4, 2011
135
0
Oh yes... that changes things. Follow this to mount the NAS at login then use the Applescript to mount the sparse bundle.

Change the mountpoint /Volumes/extDriveName section to the NAS location. Look toward the bottom of the page I linked and you will also see a way to add the network mount to the Applescript.

It is hard for me to do this without knowing what protocol you are using to share. If you post up the NAS share location, I'll try and string it all together into one script for you.
I"m using samba to share.

The NAS share location is - smb://192.168.1.10/Timemachine
The sparsebundle inside the shared location is - TimeMachine.sparsebundle

Thanks a lot for the help so far. :)
 

Weaselboy

Moderator
Staff member
Jan 23, 2005
30,419
10,218
California
I"m using samba to share.

The NAS share location is - smb://192.168.1.10/Timemachine
The sparsebundle inside the shared location is - TimeMachine.sparsebundle

Thanks a lot for the help so far. :)
Okay... try this in Applescript editor..

Code:
try
    mount volume "smb://192.168.1.10/Timemachine"
end try
do shell script "hdiutil attach -mountpoint smb://192.168.1.10/Timemachine TimeMachine.sparsebundle"
 

Namtaro

macrumors regular
Original poster
Dec 4, 2011
135
0
Okay... try this in Applescript editor..

Code:
try
    mount volume "smb://192.168.1.10/Timemachine"
end try
do shell script "hdiutil attach -mountpoint smb://192.168.1.10/Timemachine TimeMachine.sparsebundle"
Hmm, gave me a 'hdiutil: attach failed - No such file or directory' error.

Used this and it looks to be working. Just added 'Volumes/TimeMachine/' before the sparsebundle
Code:
try
	mount volume "smb://192.168.1.10/Timemachine"
end try
do shell script "hdiutil attach -mountpoint smb://192.168.1.10/Timemachine Volumes/TimeMachine/TimeMachine.sparsebundle"
Do I save the Applescript somewhere and drag it into loginitems?
 
Last edited:

Weaselboy

Moderator
Staff member
Jan 23, 2005
30,419
10,218
California
Hmm, gave me a 'hdiutil: attach failed - No such file or directory' error.

Used this and it looks to be working. Just added 'Volumes/TimeMachine/' before the sparsebundle
Code:
try
	mount volume "smb://192.168.1.10/Timemachine"
end try
do shell script "hdiutil attach -mountpoint smb://192.168.1.10/Timemachine Volumes/TimeMachine/TimeMachine.sparsebundle"
Do I save the Applescript somewhere and drag it into loginitems?
Excellent!

Yes... just save as an Applescript where ever you want. Documents is fine. Then just add it as a login item. All set. :)
 

Namtaro

macrumors regular
Original poster
Dec 4, 2011
135
0
Excellent!

Yes... just save as an Applescript where ever you want. Documents is fine. Then just add it as a login item. All set. :)
Hmm, seems it doesn't work. When I save the script and add it as a login item, it only opens the script and doesn't actually run it. I have to manually press 'run'. :(

Nevermind, found the solution - I had to export it as an Application :)

Thanks for all the help, Weaselboy!
 
Last edited:

CJSF2323

macrumors newbie
Apr 10, 2017
2
0
This has been super helpful thus far, but I'm getting an error message saying "hdiutil:attach failed - no mountable file systems"

Here's what I've got in my AppleScript:

try

mount volume "smb://192.168.0.1/volume2"

end try


do shell script "hdiutil attach -mountpoint smb://192.168.0.1/volume2 /Volumes/volume2/TimeMachine.sparsebundle"

I have a password saved to access this in my keychain, which I'm thinking could be the issue. I'm a complete novice though, so any help is appreciated!

upload_2017-4-10_16-26-10.png
 

chrfr

macrumors G3
Jul 11, 2009
9,667
3,523
This has been super helpful thus far, but I'm getting an error message saying "hdiutil:attach failed - no mountable file systems"
hdiutil is not an appropriate tool to connect to a server. What, exactly, are you trying to do?
 

CJSF2323

macrumors newbie
Apr 10, 2017
2
0
hdiutil is not an appropriate tool to connect to a server. What, exactly, are you trying to do?
Automatically backup my Mac via Time Machine on my network drive.

Copied then modified the code from Weaselboy's post on 11/26/12.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.