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

10.5: A script to find what's using a CD or DVD System
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).]
    •    
  • Currently 1.43 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[5,230 views]  

10.5: A script to find what's using a CD or DVD | 4 comments | Create New Account
Click here to return to the '10.5: A script to find what's using a CD or DVD' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: A script to find what's using a CD or DVD
Authored by: RickoKid on Sep 03, '09 01:03:13PM
I created an AppleScript called Eject Disks to help eject troublesome disks, which also will inform you which application is preventing a disk ejection using LSOF.

---
Visit my technology (and Apple in particular) blog at http://tumbleseed.torrfamily.org/

[ Reply to This | # ]

10.5: A script to find what's using a CD or DVD
Authored by: zabouti on Sep 03, '09 02:40:24PM

On my mac (Macbook Pro 10.5.8), the drutil command also returns a "Book Type", so I modified the line that runs it to say:

dr=($(drutil status | grep -i 'type:' | head -1 ))

-- ge



[ Reply to This | # ]
10.5: A script to find what's using a CD or DVD
Authored by: Anonymous on Sep 04, '09 10:47:55AM

Not at a Mac, so I can't see what the output of drutil looks like, but you probably want "^type:" as the regex, rather than piping to head -1; just in case they change the order or add other fields. Or you could pipe through another grep -i -v "Book Type:" to exclude "Book Type:".



[ Reply to This | # ]
10.5: A script to find what's using a CD or DVD
Authored by: everkleer80 on Sep 10, '09 10:59:12AM

This is great! I have run into and been frustrated by this issue multiple times before, never with CDs, but with external drives. When I found out this feature was in Snow Leopard, I knew right away that the upgrade was worth it!



[ Reply to This | # ]