Having a CD or DVD stuck in your Mac or optical drive is no fun. If you’ve tried ejecting the disc using File > Eject, the Eject key, and restarting your Mac to no avail, it’s time to turn to the Terminal app for help. You can use Terminal to force-eject the CD or DVD without shutting down your Mac using the drutil and diskutil commands.
Terminal Tip Tuesday – Force Eject a Stuck Disk/CD from the Optical Slot
Terminal, an app that comes with Mac OS, provides access to the Mac’s command line. The fact that the Mac has a command line often comes as a shock to Mac users and Windows switchers, but when you realize that OS X and macOS are built with Unix components, it makes sense that a command line tool would be available.
Terminal contains commands for working with attached storage devices, such as an optical drive.
You can use diskutil's ability to work with optical drives to force eject stuck media in your optical drive. If your Mac has a single optical drive with a stuck disk, the simple approach will probably work for you.