Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I need to add functionality to my script that should unmount cdrom and eject it. How I can achieve this in Perl? (In don't have MacOSX to test, that's why I'm asking!)

Thank you very much in advance!

  • Comment on How to umount and eject cdrom on MacOSX from Perl?

Replies are listed 'Best First'.
Re: How to umount and eject cdrom on MacOSX from Perl?
by Thilosophy (Curate) on Feb 10, 2005 at 11:02 UTC
    Interesting question. I do not really know. Just to get the ball rolling:

    You could use AppleScript to tell the Finder to eject the CD. Call this AppleScript from Perl using the "osascript" command line shell (or using Mac::Glue).

    Or the 'disktool' command: disktool -e disk2. You need to know the name of the disk, however (disktool can also list the disks currently mounted).

Re: How to umount and eject cdrom on MacOSX from Perl?
by mkirank (Chaplain) on Feb 10, 2005 at 12:19 UTC
Re: How to umount and eject cdrom on MacOSX from Perl?
by ambrus (Abbot) on Feb 10, 2005 at 09:13 UTC
Re: How to umount and eject cdrom on MacOSX from Perl?
by Anonymous Monk on Feb 10, 2005 at 14:05 UTC
    man drutil

    $ret = `drutil tray eject`; # if you have only one tray

Re: How to umount and eject cdrom on MacOSX from Perl?
by Anonymous Monk on Feb 10, 2005 at 11:47 UTC
    Thanks for arriving answers! And is 'umount' utility (non syscall!) at all exists on macosx? Can I call it at least to umount cdrom (and ask user to press the eject button manually)? Can I invoke it like this: system("umount $some_drom_mountpoint"); - is it always in $PATH; do all users have the right to invoke it? Will it succeed if Finder window is opened for CDROM folder?
      I believe that the umount command exists on all versions of Mac OS X. However, it will not unmount a mounted CDROM volume but, rather, returns a "Operation not permitted" error.

      A better solution is the one offered by the AM below, use the drutil command. This command should unmount the mounted CDROM volume and eject the CDROM. It doesn't matter if a Finder window is currently displaying the contents of the CDROM volumes. Read the drutil man page for dealing with multiple CDROM drives.