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

An AppleScript to unmount multiple volumes at once System
I very often have a lot of different Volumes (hard disks, disk images, ROMs, Servers, etc.) mounted. To eject a single partition on a hard disk, I need help from Disk Utility. And in the Finder's sidebar, only removable volumes are ejectable. The same is true in open/save dialogs. I can eject any volume in the Terminal, but I have to know the correct command (umount, hdiutil, disktool, etc.). This procedure is very painful when I want to unmount many different volumes of different types.

So I created this AppleScript to eject all the selected volumes within a second (except my Startup disk, of course!). For each "disk unmount command," the script opens a new Terminal window to eject the volume. This may be annoying, but it's fast. The more elegant way is not to tell Terminal to execute the command, but to do it directly with the Script:
do shell script "disktool -e disk2"
This works, but it takes more than 15 seconds to eject one volume -- and there is no error message if something goes wrong. Servers are unmounted this way, that works very smooth. I don't know why the behavior of the commands differs if executed by Terminal or by System Events. And finally: An image ejected by this script can be remounted easily -- without the help of Disk Utility.
    •    
  • Currently 1.80 / 5
  You rated: 1 / 5 (5 votes cast)
 
[19,194 views]  

An AppleScript to unmount multiple volumes at once | 10 comments | Create New Account
Click here to return to the 'An AppleScript to unmount multiple volumes at once' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to unmount multiple volumes at once
Authored by: erikh on Oct 26, '04 02:10:33PM

You might find that iTerm is preferred for this, terminal-wise. It has much better controls in the AppleScript department.

A couple of other ideas:

Write a shell script to do it, and if you want a gui element, have the terminal call that.

There are a few "mount" AppleScript commands that come with the Scripting Addition #1. You might want to look there for something that beats all these scenarios.



[ Reply to This | # ]
A couple of other ideas
Authored by: platon on Oct 27, '04 12:30:56PM

Thx for your input.
When I find some time, I will try do write a shellscript to do the job. (Since I run Terminal instead of Finder, it's no problem for me to have a lot of Terminal-Windows opened.)



[ Reply to This | # ]
An AppleScript to unmount multiple volumes at once
Authored by: hypert on Oct 26, '04 09:43:50PM
I haven't examined this entire script, nor looked at the exact capabilities of the "disktool" terminal command, but the script seems a little over-kill. I've been using this simple script to eject scripts, and it uses all AppleScript (no system/terminal calls).

tell application "Finder"
	set bootDisk to name of startup disk
	set otherDisks to every disk whose (name is not bootDisk) and (name is not "Media")
	repeat with myDisk in otherDisks
		try
			eject myDisk
		end try
	end repeat
end tell
This ejects everything except your boot disk, and a disk called "Media", in my example. Feel free to build your own exception list by just modifying and adding on to the otherDisks definition.

[ Reply to This | # ]
the script seems a little over-kill
Authored by: platon on Oct 27, '04 04:29:02PM

What's about ejecting CD- or DVD-Rom's. What's about a partition which resides on the same Harddisk like your Startup-Partition. What's about to not eject every disk but to select them.



[ Reply to This | # ]
Unmount selected disks
Authored by: sinjin on Oct 28, '04 02:37:42PM
Regarding the applescript by hypert, the following change will eject only selected disks. In trying it out I noticed that it will only eject ejectable items (iPods, dmg, shares, removable disks), so no need to exclude the startup volume or anything else for that matter. i.e. if you mistakenly select files or folders, the Finder seems to ignore them and continue ejecting everything else. Not sure how it deals with partitions, I don't have any.


tell application "Finder"
	set selectedDisks to selection
	repeat with myDisk in selectedDisks
		try
			eject myDisk
		end try
	end repeat
end tell

I have no idea if this covers the functionality of platon's original script (I suspect it may not), but present it as a solution that works for me.

[ Reply to This | # ]

Thanks, with iKey your applescript makes it easy to unmount external Hard Drives
Authored by: peterrosen on Apr 12, '06 04:03:29PM
Thanks for your script, it works like a charm. When I call it, saved as an application using iKey, I can unmount my external HD's with a keystroke. since I am always connecting and disconnecting my laptop, this comes in real handy. If I feature this tool over at Creativity Cafe, I'll let you know. Aloha, Peter

[ Reply to This | # ]
An AppleScript to unmount multiple volumes at once
Authored by: designr on Oct 27, '04 01:26:50PM

And, for those that need to unmount server shares but not local disks:

tell application "Finder" to eject (every disk whose local volume is false)



[ Reply to This | # ]
unmount server shares but not local disks
Authored by: platon on Oct 27, '04 04:15:05PM

If you have mounted 10 server volumes (e.g. afp, ftp. etc) and just want to unmount 4 of them? - Use the original script posted here.



[ Reply to This | # ]
An AppleScript to unmount multiple volumes at once
Authored by: mbroughtn on Oct 27, '04 10:31:52PM

I too experienced the delay when using the form:
do shell script "disktool -e disk2

I found a message appeared in the Console log every time I used this:
Oct 27 20:58:22 Yosemite diskarbitrationd[90]: Script Editor [572]:23047 not responding.

I'm not sure what all it means, but it looks like an indication of why there is the delay. I get not such message when using the ' tell application "Terminal" ' format.



[ Reply to This | # ]
disktool is deprecated, use diskutil instead
Authored by: dzurn on May 08, '06 10:43:29AM

from "man disktool":

DESCRIPTION
This command is deprecated and exists only for backwards compatibility.

Do not use disktool, use diskutil instead.


---
Madness takes its toll.
Please have exact change.



[ Reply to This | # ]