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


Click here to return to the 'Use disktool and System Profiler to eject stubborn CDROM discs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use disktool and System Profiler to eject stubborn CDROM discs
Authored by: Eravau on Dec 12, '03 09:47:11AM
Ok...it took me a few minutes to realize what the problem was (i.e. that there is no BSD name for a disk that's not there, so it just went 'til it found any BSD name after finding a removable media drive). Here's the re-write (on top of pmccann's edits) with the appropriate modification to stop it from hitting the wrong disk when there's no removable media in the first drive it hits...


#!/usr/bin/perl

use warnings;
use strict;

#  Get The Info For All IDE, USB, & FireWire Devices
# ---------------------------------------------------
my @profile_data = `/usr/sbin/system_profiler SPIDEDataType SPUSBDataType SPFireWireDataType`;
my $found;

#  Find The First CD/DVD and Eject It
# ------------------------------------
foreach (@profile_data) {
	$found = 1 if /Drive Type.* CD-R/;
	$found = 0 if ($found && /^\S/);
	if ($found && /BSD Name.* (disk\S+)/){
		my $bsd_name=$1; 
		print "Ejecting $bsd_name\n";
		system ("/usr/sbin/disktool -e $bsd_name > /dev/null");
		exit;
	}
}
print "No disk found to eject.\n";

Sorry about the problems there.

[ Reply to This | # ]
Use disktool and System Profiler to eject stubborn CDROM discs
Authored by: ber on Apr 01, '04 11:34:11PM

No harm at all. Thanks for the update. If I knew how to get mail notification on responses to things I post I'd have checked back here long ago. Appreciate your efforts.

brian



[ Reply to This | # ]