Have you ever tried to eject a CD or DVD and were told that the disk was in use and couldn't figure out what was using the disk? After helping others answer this question, I created this shell script to provide the answers.
#!/bin/bash
PATH=${PATH}:/sbin:/usr/sbin
dr=($(drutil status | grep -i 'type:'))
devtype=${dr[1]}
device=($(mount | grep ${dr[3]}))
if [ $devtype = "No" ]
then echo No disk found. Sorry! >&2
exit 1;
fi
echo A $devtype is mounted on the device named $device
pids=($(sudo -p 'Please enter the administrator password:' lsof -t $device))
echo \nList of programs that may be preventing the disk to eject
ps -o pid,user,comm=COMMAND -www -p $(echo ${pids[*]} | sed 's/ /,/g')
The output is a list of the processes that lsof says is using the CD or DVD. You can probably plug this into GeekTool or some other GUI assist program; I just use the terminal.
[robg adds: Snow Leopard should provide this information automatically, so I marked this one as 10.5 only (though it probably works on 10.4, too). I tested on my 10.5 machine, and it seemed to work (though I didn't have a busy CD/DVD at the time of testing). Remember to make the script executable (chmod a+x script_name).]

