Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'AppleScript to Force-mount unmountable disk images' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScript to Force-mount unmountable disk images
Authored by: Frederico on Sep 16, '04 12:29:27AM
It just so happens that we already built an AppleScript solution using this method; I'll paste it below for those who are Terminally challenged. As for the issue with password protected disks, this script will indeed trigger a GUI window asking for any such passwords not already stored in Keychain. I have yet to find an instance where presentation of the password box triggered the failure we're looking to overcome in this hing, but the -stdinpass switch would likely resolve it (see the man page), and could be added to this script.

set theDMG to POSIX path of (choose file with prompt 
	"Where is the .DMG file or files you wish to mount?" of type {"devi", "devr"} 
	with multiple selections allowed)
set {a, b, c} to {"Cancel", "Verify", "Skip Verification"}

set verifyOption to button returned of 
	(display dialog "Would you like to skip verification? (recommended)" & return & return & 
		"CAUTION: verification can take a very long time, and you will receive no feedback or opportunity to cancel once selected." buttons {a, b, c} 
		default button 3 with icon 2)

if verifyOption is b then set verifyOption to " "
if verifyOption is c then set verifyOption to " -noverify "
set mountDMG to "sudo hdiutil attach" & verifyOption & theDMG
try
	do shell script mountDMG with administrator privileges
	display dialog "Disk Mount of disk image " & (theDMG as text) 
		& " is complete."
on error errMSG
	display dialog errMSG
end try

Sorry about the code wraps, Rob, I tried to install AS returns, but they wouldn't deal with the line wraps any better because of the parentheticals.

[ Reply to This | # ]
AppleScript to Force-mount unmountable disk images
Authored by: Frederico on Sep 16, '04 12:45:38AM
[Rob, you can delete the post above (when are we going to get edit privileges?) if you want; I modified the script to fit nicely--F]

It just so happens that we already built an AppleScript solution using this method; I'll paste it below for those who are Terminally challenged. As for the issue with password protected disks, this script will indeed trigger a GUI window asking for any such passwords not already stored in Keychain. I have yet to find an instance where presentation of the password box triggered the failure we're looking to overcome in this hing, but the -stdinpass switch would likely resolve it (see the man page), and could be added to this script.

set theDMG to POSIX path of (choose file with prompt 
	"Where is the .DMG file or files you wish to mount?" of type {"devi", "devr"} 
	with multiple selections allowed)
set {a, b, c} to {"Cancel", "Verify", "Skip Verification"}
set msg1 to "Would you like to skip verification? (recommended)" & return & return
set msg2 to "CAUTION: verification can take a very long time, and you will"
set msg3 to "receive no feedback or opportunity to cancel once selected."
set verifyOption to button returned of 
	(display dialog msg1 & msg2 & msg3 buttons {a, b, c} 
		default button 3 with icon 2)
if verifyOption is b then set verifyOption to " "
if verifyOption is c then set verifyOption to " -noverify "
set mountDMG to "sudo hdiutil attach" & verifyOption & theDMG
try
	do shell script mountDMG with administrator privileges
	display dialog "Disk Mount of disk image " & (theDMG as text) 
		& " is complete."
on error errMSG
	display dialog errMSG
end try



[ Reply to This | # ]
AppleScript to Force-mount unmountable disk images
Authored by: Frederico on Sep 16, '04 06:03:29AM
Man, it is amazing how fast folks around here report bugs. Sorry for the oversights; the script was originally written for single DMGs, and I added multiples without really testing it or thinking it through; also we rarely use a special character in a file path because we're so used to working on the web. All bugs should be resolved, except those idiosyncracies that exist with name problems in hdiutil (such as "image already specified" errors).

set theDMGs to (choose file with prompt 
	"Where is the .DMG file or files you wish to mount?" of type {"devi", "devr"} 
	with multiple selections allowed) as list
set {a, b, c} to {"Cancel", "Verify", "Skip Verification"}
set msg1 to "Would you like to skip verification? (recommended)" & return & return
set msg2 to "CAUTION: verification can take a very long time, and you will"
set msg3 to "receive no feedback or opportunity to cancel once selected."
set verifyOption to button returned of 
	(display dialog msg1 & msg2 & msg3 buttons {a, b, c} 
		default button 3 with icon 2)
if verifyOption is b then set verifyOption to " "
if verifyOption is c then set verifyOption to " -noverify "
try
	do shell script "sudo df -k" with administrator privileges -- just here to get sudo rights only once
on error errMSG
	display dialog errMSG & return & "Please try again." as string
	return
end try
with timeout of 60000 seconds
	repeat with i from 1 to number of items in theDMGs
		set theDMG to item i of theDMGs
		set mountDMGs to "sudo hdiutil attach" & verifyOption & "\"" & 
			(POSIX path of theDMG) & "\""
		try
			do shell script mountDMGs
			display dialog "Disk Mount of disk image " & return & (theDMG as text) 
				& " is complete." giving up after 4
		on error errMSG
			display dialog errMSG
		end try
	end repeat
	if (number of items in theDMGs) is greater than 1 then 
		set endOpt to button returned of (display dialog 
			"All operations complete" & return & return & 
			"Send comments to frederico@mac.com" buttons {"Comments", "Cool"} 
			default button 2)
	if endOpt is "Comments" then open location "mailto:frederico@mac.com"
end timeout



[ Reply to This | # ]
AppleScript to Force-mount unmountable disk images
Authored by: clith on Sep 21, '04 12:47:53PM

Now, if you could add an "on open" handler that handled drag-and-drop, you'd be all set! Just drag your dmg files onto the script and they would mount. No file dialog to get in the way.. :-)



[ Reply to This | # ]
AppleScript to Force-mount unmountable disk images
Authored by: mlaurenc on Mar 12, '05 11:58:16PM

Hi there...

Well, I tried both versions of your script on several disk images (including one that I KNOW mounts fine by itself), and most of them were grayed out in my file dialog. My first thought was that perhaps they were corrupted, but at least one of them mounts fine on its own, and it was not accessible either.

I very much appreciate your scripting skills, but do you have any idea why I might be having such problems? Any suggestions from anyone else out there? I would really appreciate the help!

Thanks in advance,

mlaurenc



[ Reply to This | # ]
AppleScript to Force-mount unmountable disk images
Authored by: slickseth on Jan 02, '05 10:48:43PM

I may just be a big newbie, (and I undoubtably am), but when running this script the only items I could select when it asked me which DMG I wanted to mount were file folders and no DMG files. Even with a foler selected, "Choose" never highlit. Am I doing something wrong?

Also, is there an applescript super newbie thread I should be hitting up before getting to knee deep in this?

by the way, rebooting still didn't allow me to mount the DMGs. I'm running 10.3.7.

Thanks for any/all help guys!

-Seth



[ Reply to This | # ]
AppleScript to Force-mount unmountable disk images
Authored by: slickseth on Jan 02, '05 10:48:59PM

I may just be a big newbie, (and I undoubtably am), but when running this script the only items I could select when it asked me which DMG I wanted to mount were file folders and no DMG files. Even with a foler selected, "Choose" never highlit. Am I doing something wrong?

Also, is there an applescript super newbie thread I should be hitting up before getting to knee deep in this?

by the way, rebooting still didn't allow me to mount the DMGs. I'm running 10.3.7.

Thanks for any/all help guys!

-Seth



[ Reply to This | # ]