How To Mount a Disk Image Inside a Folder Instead of On Desktop?

Hi Friends… I'm creating an encrypted sparsebundle disk image which will sit inside a folder inside the Documents Folder. Typically, clicking on the disk image would display a password prompt, which, entered correctly, would mount the image on the Desktop (default). How does one program the disk image to mount instead, inside the same folder as the disk image itself, or in a another folder, otherwise stated… How do you make a disk image mount in a location other than the Desktop? I don't see a way to do it using Disk Utility. Is it possible with Automator or Applescript? If so, can you point me to an Automator routine or particular Applescript? Thanks!

MacBook Pro, Mac OS X (10.7.5)

Posted on Jun 14, 2015 6:35 AM

Reply
4 replies

Jun 14, 2015 5:03 PM in response to KiteSurfer

Here is an idea.


Create your sparsebundle disk image


Mount your sparsebundle disk image


select a file on folder in the mounted sparsebundle disk image and create an alias for that file or folder (Command-Option-Click-AND-Drag the selected item to another folder outside of the sparsebundle disk image


Dismount (eject) the sparsebundle disk image


Now when you double-click on the Alias your sparsebundle disk image

will mount and you will have access to the sparsebundle disk image

via the alias that you can put anywhere you like.


Yes, the sparsebundle disk image will still mount on the desktop, but you will still be accessing it via an alias stored somewhere else.


And if you change the Finder -> Preferences -> General -> Show these Items on the Desktop to NOT show "External Disks", your sparsebundle disk image will not show on the Desktop.


If you do not like that, then you can start researching the autofs capabilities. Google "mac os x autofs" and check out some of the links for ideas about configuring autofs.

Jun 15, 2015 2:23 PM in response to BobHarris

Hmmm… BobHarris… interesting workaround though doesn't really address the OP and does not allow any disk image or external HD to be seen on the desktop. All I'm trying to do is get a disk image to mount in a folder rather than on the desktop. There must be an Applescript for that. I've been googling that very thing because I'm not comfortable mucking about in the terminal, but no luck yet… but thanks BH. I appreciate it.

Jun 15, 2015 3:57 PM in response to KiteSurfer

If you are willing to have an Automator or Applescript issue a Terminal command, you may be able to use the /usr/bin/hdiutil command. See "man hdiutil"


The basic form would be:


mkdir -p /the/path/to/your/mount/directory/

/usr/bin/hdiutil attach -mountroot /the/path/to/your/mount/directory /path/to/the/sparsebundle


There Automator (Run Shell Script) and Applescript (do shell script) ways to execute shell (or as you say Terminal, or as I say Unix) commands.


Of course this is complicated because you want to use an encrypted sparsebundle, and that adds complications. Try doing Google searches for "hdiutil mount encrypted image"


When I gave the hdiutil attach command a try (for an normal .dmg file - NOT encrypted), it showed up in the Finder side-bar, so I was able to unmount it by clicking on the eject icon in the Finder Side-Bar.


The other ways to unmount it would be an hdiutil detach ... command, or a Unix umount command. In both cases you have to find out the device name, which are more terminal commands, so using the Finder Side-Bar to unmount it is easier.

Jun 15, 2015 8:54 PM in response to BobHarris

Below is an Applescript for mounting multiple sparsebundle disk images on the Desktop, all linked to a single password. When the app is launched, a password window appears, the password is entered and several disk images mount sequentially on the desktop. I've only included the Applescript for the first disk image, diskname1. The formating below does not match compiled Applescript but I have no way to change the colors of the fonts here.


The "Tell Application"… thru "End Tell" sequence repeats itself for diskname2 - diskname10 and the app works very well.


property diskname1 : "Clients"

property diskpath1 : "Macintosh HD:Users:Batman:Documents:DiskImages:Clients.sparsebundle"

on run

set thePassword to "none"

set passwordBox to display dialog "Enter the password:" buttons {"Cancel", "OK"}

default button {"OK"} default answer "" with icon 2 giving up after 30 with

hidden answer

if gave up of passwordBox is true then

set myButton to "Cancel"

quit

else

set thePassword to the text returned of passwordBox

end if

tell application "Finder"

if not (exists the disk diskname1) then

do shell script ("hdiutil attach " & quoted form of ¬

POSIX path of (diskpath1 as string) & " -mount required -passphrase "

& thePassword)

repeat until name of every disk contains diskname1

delay 0.1

end repeat

end if

end tell

[diskname2 - diskname 10 sequences repeat here…]

endrun

I found another piece of Applescript online, intended to mount a disk image inside the documents folder. I've tried incorporating it into the script above to make it mount multiple disk images in the Documents folder instead of on the Desktop, but have not yet succeeded. Can anyone merge these two Applescript sequences to make a single, working script that mounts (sets the mount point for) multiple disk images to be inside the Documents folder?

set _mountLocation to POSIX file "/Users/<username>/Documents/"

mountdisk image_filemount location_mountLocation

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How To Mount a Disk Image Inside a Folder Instead of On Desktop?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.