As long as the shortcut is on your desktop you shouldn’t have to restart anything for the hotkey to work. On the Shortcut tab you’ll see a place to assign the Shortcut key:Īdd in the shortcut key and close the dialog. Now that we have a shortcut, we can assign a hotkey to the shortcut by right-clicking on the icon and choosing Properties. You can follow the same exact instructions as above, but instead of “cdrom open” just substitute “cdrom close”. You can move the icon to anywhere you’d like… double-clicking on it will immediately eject the drive.Ĭreate a Shortcut to Close the CD/DVD Drive
Keyboard shortcut to eject dvd how to#
I'm using 19.04 now and noticed my drive was becoming unlocked upon resuming from suspend.Give the shortcut a meaningful name, like Eject CD or something like that, and you’ll have a new icon (read below on how to use the cd-rom icon as shown) Lock Drive Upon Wake From Suspend (systemd method) # lock the optical drive upon resume from suspend Paste the following into the new file: #!/bin/sh I've noticed my drive becomes unlocked again upon resuming from suspend so I created a script to ensure the drive stays locked in this case.Ĭreate the script file: sudoedit /usr/lib/pm-utils/sleep.d/99lock-optical Lock Drive Upon Wake From Suspend (pre-systemd method) You can then test the shortcut immediately. Press the key combination you want to use. Once you click it, "Disabled" changes to "New Accelerator": Name the shortcut (I used "Unlock, Eject, Relock CD")Įnter this into the "Command:" field: bash -c 'eject -i off /dev/sr0 & eject /dev/sr0 & eject -i on /dev/sr0'Ĭlick to the right of your shortcut's name where it says "Disabled".Click on the "+" sign, a new dialogue box will open.Click on "Custom Shortcuts" at the bottom of the list.Open the "Keyboard" program found within the Dash.Here's how to accomplish this keyboard shortcut: This way I can still easily access the drive but the hardware button is never a problem. But how will I open the drive when I need to use it?! To make it simple, I put the commands into an "eject" keyboard shortcut which unlocks the drive, ejects the drive, then relocks the drive. Now the optical drive is locked upon startup. Type a name (I went with the descriptive "Lock optical drive") and within the "Command:" field enter bash -c 'eject -i on /dev/sr0'Ĭlick "Add" to complete and then close the program. Open the program and then click the "Add" button, a new dialogue box opens. I used the GUI "Startup Applications" program (preinstalled in Ubuntu, find it with Dash) to accomplish this. To make this more useful, I wanted this command to take effect upon startup. Now you should be able to disable the optical drive hardware button (essentially we're locking the drive) with this:Įject -i on /dev/sr0 ~or~ eject -i 1 /dev/sr0 They do the same. Don't worry that it appears as a strange temporary file name, that's just how sudoedit works. Now save and close by pressing Ctrl+ X, then Y to confirm, followed by Enter to accept the current file name. Locate this line: ENV="?*", RUN+="cdrom_id -eject-media $devnode", GOTO="cdrom_end" Next, edit /etc/udev/rules.d/60-cdrom_id.rules and comment out the problematic line: sudoedit /etc/udev/rules.d/60-cdrom_id.rules (note: if eject -i on already works, you may skip ahead to "Lock the Drive on Startup")įirst, copy /lib/udev/rules.d/60-cdrom_id.rules to /etc/udev/rules.d/ like so: cp /lib/udev/rules.d/60-cdrom_id.rules /etc/udev/rules.d/