Making a custom keyboard shortcut in Ubuntu

Ubuntu uses a graphical interface called Gnome (sometimes you may hear it referred to as a desktop environment), which allows you to easily define keyboard shortcuts for some common commands by going to System > Preferences > Keyboard Shortcuts.

Sometimes, though, you may want to define keyboard shortcuts for custom commands that aren’t available through that menu. In this example, you’ll see how to make a keyboard shortcut for a command that will allow you to open a file browser as “root” (or the ultimate administrative user).

First, press Alt-F2. This will open a Run Application dialogue.


In that dialogue, paste the command

gconf-editor


In the Configuration Editor window that appears, click on the menu Apps and then select Metacity. Within Metacity, you’ll see several submenus. The first one you’ll select will be global_keybindings. Once you select that, you’ll see a bunch of disabled commands with numbers attached to them. Find an empty one, most probably run_command_1, click on the Value column next to it, and then type the keyboard shortcut.

You’ll have to actually type out the words describing the shortcut. You can’t, as you would in the normal Keyboard Shortcut menu, just press the key combination you want. In this case, the shortcut

<Mod4><Hyper>n

means Windows+N (or holding down the Windows key and then pressing the n key).

This assumes you’ve already made Windows a modifier key. If you haven’t yet completed that step, you can use other modifier keys like <Shift> or <Alt>


Then, again within the submenu of Metacity, select keybinding_commands, pick the corresponding empty command (since we selected run_command_1 before, we should now select command_1). For the command, we’re putting

gksudo nautilus


Now when you press Windows+N, you’ll get a password authentication dialogue to escalate to root privileges temporarily…


And then you can browse and make changes to the filesystem as root.

2 comments

Leave a comment

Your email address will not be published. Required fields are marked *