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: pmccann on Dec 11, '03 07:32:08PM
Just a quick suggestion: instead of chasing line numbers (that you're not really interested in anyway), maybe just set a flag for when you've hit the "CD-R" line, then search for the next "BSD Name" line after that. Here's a rewrite of the script with just those changes.

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/;
if ($found && /BSD Name.* (disk\S+)/){
my $bsd_name=$1; 
print "Ejecting $bsd_name\n";
system ("/usr/sbin/disktool -e $bsd_name > /dev/null");
print "No disk found to eject.\n";
Cheers, Paul

[ Reply to This | # ]