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

Click here to return to the 'A bash script to mount and unmount volumes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A bash script to mount and unmount volumes
Authored by: Titanium Man on Mar 12, '03 12:03:29AM

Nice script. I've been using the following for a while now to eject external drives, CDs, etc.

eject () {
/usr/sbin/disktool -e $(df | grep $1 | awk '{print $1}' | sed 's/\/dev\///')

You type 'eject /Volumes/name', and then it ejects.

[ Reply to This | # ]
A bash script to mount and unmount volumes
Authored by: rodbrim on Feb 25, '04 05:44:34PM

You can always do it like this from a shell session. ssh into your machine and do it remotely (if you are comfortable turning on remote login)
osascript -e 'tell application "Finder"' -e 'eject <volume name>' -e 'end tell'

[ Reply to This | # ]
The script also mounts!
Authored by: mlm on Mar 27, '04 04:51:58PM

These eject scripts -- and the technologies they use -- only eject; the bash script originally posted also mounts. I have a large but whiny Firewire drive I use only for my iTunes library. I like to mount it and dismount it according to whether I'm using it with iTunes or not. There are various little utilities out there for unmounting disks, but I don't think I've seen one that remounts and unmounted one. And I use the shell a lot, so this is perfect for what I want.

In fact, I was stuck for a name when I put this script in a file on my machine: it mounts the volume if unmounted, and unmounts the volume if mounted, so it "toggles" the mount status of the disk, but "toggle" is a bit weak a word here. I tried "switchmount", but too long and "flipmount", but too hokey. Ended up with "switchvol", which is OK, but not great -- suggestions?

Actually, it doesn't really matter what I called it because I made a shell alias whose name was the same as the disk, so now I can mount/unmount my iTunes library disk with just a one-word command.

Thanks for working this out. There are a lot of ways to get at volume information, and it isn't always easy to find what you want in a reasonable form. The approach here is direct (maybe even crude), but it would be difficult to improve on it. I could use Mount Me! (or something like it) to mount my disk and DocJector (or something like) to eject it, which I do sometimes, but when I know which disk I want to mount/unmount, and I switch frequently I'd be just as happy to have a direct shell script.

--- Mitchell

[ Reply to This | # ]