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

Unmount a volume (on login) via AppleScript System
I was looking for a way to unmount a volume which appears on the Desktop immediately after logging in Mac OS X 10.4 (Tiger) for security reasons (it's a rescue volume with a plain system on it), and came across this hint from Norm Nager: A script to unmount cloned backup volumes at login.

All attempts to use Norm's script failed for me. I have no idea why, so I tried something else. Even with Automator, it did not work, so I ended up with this little AppleScript:
tell application "Terminal"
  activate
  do script 
   "diskutil unmount \"/Volumes/volumename to unmount\"" in 
   window frontmost
  delay 5
  quit
end tell
It activates Terminal, invokes Apple's command line tool diskutil in the frontmost window of the Terminal app, unmounts the Volume with the name Volumename to unmount, waits five seconds (until the unmount progress is finished, otherwise a sheet opens and asks for user interaction, which is very inconvenient), and then quits the Terminal.

The script works fine for users with administrator accounts, but standard accounts do have to enter an admin name and admin password. So it's not an all-rounder. If there is anyone who has an idea how to unmount volumes in Tiger while logging in as a standard user, please help me.
    •    
  • Currently 3.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[21,296 views]  

Unmount a volume (on login) via AppleScript | 14 comments | Create New Account
Click here to return to the 'Unmount a volume (on login) via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Unmount a volume (on login) via AppleScript
Authored by: pgaulrapp on Feb 23, '06 08:14:06AM

You can prevent it from ever mounting in a managed user's account.

From an admin account, get info on the volume and show details for Ownership and Permissions. In the "Owner" popup menu, make sure you are the owner. Changing the ownership to yourself won't hurt anything as long as it's not the boot volume (in my experience). In the "Others" popup menu, choose "None". After this, close the info window and reboot into the managed account. The volume shouldn't mount.



[ Reply to This | # ]
Hiding partitions / volumes
Authored by: Hal Itosis on Feb 23, '06 09:14:04AM
There's also the filesystem table (fstab) method, outlined nicely at www.MacGeekery.com.

Easily done on Tiger... but Panther's Disk Utility doesn't seem to display UUIDs.
(If anyone knows how to read volume UUIDs in Panther, please reply with info).

-HI-

[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: vocaro on Feb 23, '06 10:00:26AM

Why don't you just do:

tell application "Finder"
eject disk "volumename to unmount"
end tell



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: claudio on Feb 23, '06 02:33:56PM

I tired that easy looking script over and over again - nothing happend on my system.
The scripteditors' event-protocol showed me no errors, but the drive remains on the desktop.
Sad but true.

---
- claudio



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: swilcox on Feb 23, '06 02:40:21PM

That's weird. I just tried the script and it consistently works to unmount a volume on my server. Handy tool. Thanks!



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: sjk on Feb 23, '06 08:41:56PM

If your volume is mounted as /Volumes/Volname try:

eject disk "Volname"

Using the full "/Volumes/Volname" pathname doesn't work.



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: doneitner on Feb 23, '06 05:57:27PM

Man, I'm still trying to find a good way to mount a (network shared) volume on login, and you're talking abount UNmounting one. :) I suppose this could be good, though, for ejecting a CD/DVD before any kind of auto-run occurs.



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: sloth on Feb 23, '06 09:39:56PM

Create an alias to the volume and then add it to the login items for the user. It will mount the volume upon login.



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: regulus on Feb 24, '06 12:08:13AM

I used to use an alias to accomplish this, but I found that the alias would stop working after a time. I couldn't figure out why the alias would stop working but it happened a lot. So I finally wrote this applescript and saved it as an application as run only... it works every time. Then just add it to your login items and you're all set.

-------------------------------------------
tell application "Finder"
if not (exists disk "VolumeName") then open location "afp://username:password@ip_address/VolumeName"
end tell
-------------------------------------------

Note: the if not statement first checks if the volume is already mounted, because if it is then you'll get a dialog box telling you that it's already mounted and thus you have to click "OK" to get rid of the dialog box... which is a pain.

Hope this helps.



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: Shane Palmer on Feb 23, '06 06:52:26PM
You can also perform the shell command without ever needing to launch Terminal by using the do shell script command so your full script would look like this:
do shell script "diskutil unmount \"/Volumes/volumename to unmount\""
Since this uses a scripting addition there is no need to have a tell block either. There are several other options with the do shell script command that will allow you to prompt for an admin username and password. To get more info on this command in Script Editor go to File-->Open Dictionary... and select Standard Additions. It is located in the Miscellaneous commands section. This will at least allow you to get it to a point where no user interaction is required and the user won't even notice anything happening other than the script icon in the dock, unless you tell it to prompt for a password.

[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: TigerKR on Feb 23, '06 10:26:55PM

I achieved this result using a Platypus application that I have added to my login items. Here is the script that I embedded into the Platypus application:

#!/bin/sh

sleep 1

diskutil unmount /Volumes/Foo
diskutil unmount /Volumes/Bar

exit

http://www.macupdate.com/info.php/id/12046



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: TigerKR on Feb 27, '06 11:03:25AM

There is some interesting conversation on this topic in another thread also:

http://www.macosxhints.com/article.php?story=2005052804075538



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: kingantoine on Dec 19, '06 06:34:33PM

Has anyone come up with a fast and efficient shell script yet? I successfully used the Platypus method mentioned but it takes too long to unmount the other volumes.



[ Reply to This | # ]
Unmount a volume (on login) via AppleScript
Authored by: kingantoine on Dec 19, '06 06:55:39PM

Has anyone come up with a fast and efficient shell script yet? I successfully used the Platypus method mentioned but it takes too long to unmount the other volumes



[ Reply to This | # ]