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


Click here to return to the 'A script to unmount cloned backup volumes at login' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to unmount cloned backup volumes at login
Authored by: PCheese on Oct 17, '04 04:38:34PM
Here's my version. The main difference is that if you run it after using it once to unmount a disk, it'll remount the disk for you, although it'll look like a disk image (but you will be making changes to the disk itself, only the icon should be different). I had to add a whole bunch of line continuation characters.

(*
   Simple unmount volume script
   By PCheese
   10/17/2004
   Useful to unmount a disk at login
   You must set the variable volumeName to the name of your disk.
   If you would like to mount the volume without having to type in a password,
      save your password in the savedPassword variable. Please be aware that this
      is insecure, and someone with access to this script could recover your password
      if you save it, even if you save the script as run-only.
  Set delayTime to something higher if you have trouble with this script at startup
*)
property volumeName : "Macintosh HD"
property savedPassword : ""
property delayTime : 0

property lastDevicePath : ""

on run
	set previousDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to " "
	-- this part is just so we can mount it again later
	try
		set matchingVolumes to do shell script "df | grep '/" & volumeName & "$'"
		set matchingVolumes to every text item of matchingVolumes
		--less than ten characters would be a mounted disk image
		if (count characters in item 1 of matchingVolumes) is greater than 10 then
			set lastDevicePath to item 1 of matchingVolumes
		end if
		-- now unmount it for real after waiting some delay time for the Finder
		delay delayTime
		try
			tell application "Finder" to eject disk volumeName
		end try
	on error errMes number errNum
		if errNum is 1 and lastDevicePath is not "" then
			try
				set baseDialogText to "The volume named \"" & volumeName & "\" last located on " & lastDevicePath ¬
& " seems to be unmounted.  Would you like to mount it as a disk image now?"
				if savedPassword is not "" then
					display dialog baseDialogText buttons {"Cancel", "Mount"} default button 2 with icon caution ¬
 giving up after 60
					do shell script "hdiutil mount " & lastDevicePath & " > /dev/null" password savedPassword ¬
 with administrator privileges
				else
					display dialog baseDialogText & return & return ¬
& "You will have to type an administrator password." ¬
buttons {"Cancel", "Mount"} default button 2 with icon caution ¬
giving up after 60
					do shell script "hdiutil mount " & lastDevicePath & " > /dev/null"
				end if
			end try
		end if
	end try
	set AppleScript's text item delimiters to previousDelimiters
end run


[ Reply to This | # ]