"Emergency"-Eject

Well, this script saved me sometimes - so I’d like to share it. The purpose is simple: Sometimes you may run into a situation where something went wrong while mounting or ejecting a CD/DVD/etc. You are left with no Volume mounted on the desktop but the media stuck in the device. The eject-key on the keyboard wouldn’t work… at least this happens to me once in a while.



set d_list to do shell script "drutil list"
set d_cont to paragraphs 2 thru (number of paragraphs in d_list) of d_list
set device_list to {}

repeat with i in d_cont
	set this_i to (i as text)
	if number of words in this_i > 2 then
		set device_list to device_list & (word 3 of (i as text))
	end if
end repeat

set choice to choose from list device_list with prompt "Eject media from which device?" without multiple selections allowed and empty selection allowed

if (class of choice = list) then
	repeat with i from 1 to (number of items in device_list)
		if ((item i of device_list) as text) = ((item 1 of choice) as text) then
			do shell script "drutil tray eject " & i
			exit repeat
		end if
	end repeat
end if


I’m not sure if this works with other devices than my built-in Apple-DVD-burner as I have no additional hardware to test it.
I would appreciate any comments, rants, error-reports or whatever. :slight_smile:

Model: PowerMac G5 2.3GHz Dual
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

I’ve had a CD stuck in my Mac Mini for ages. Thank you so much!

Good script. It opened the trays to my internal and external drives. Instead of the Cd and DVD options I think that it would be a lot cooler if the names of the drives were listed instead. For instance in my case it would be- HL-DT-ST DVD-RW GWA-4082B & TSSTcorp CD/DVDW SH-S162L. Here’s another script that performs the same function- (do shell script “drutil tray eject”).

Works as advertised in Leopard, too. :smiley:

awesome - my mini does this all the time and I have to reboot - so annoying! I LOVE THIS SITE!

It takes a while on badly damaged CDs (most of the CPU load is Finder trying to read the doggone disk :stuck_out_tongue: ), but otherwise it works like a charm!

Model: Macbook
AppleScript: 2.0.1
Browser: Safari 533.22.3
Operating System: Mac OS X (10.5)

On a related note, my laptop immediately ejects any blank DVDs I insert.