Add custom keybindings for any command

This document (7023429) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Desktop or Server 12 using the GNOME Desktop

Situation

Custom hotkey or key binding would like to be created for running a specific application or command.

Need to script the process to provide the key binding to other systems.

Resolution

For this example let's say that we want Super Key+e to bring up the file browser (similar to some other OS).

The graphic method in Gnome is to select from the menu 'System Tools --> Settings' then under 'Hardware' select 'Keyboard'.

In the Keyboard settings select 'Custom Shortcuts' on the left and click the + button near the bottom.  Enter a name for the shortcut (let's use 'File Browser') and what command to run which in this case is 'nautilus'.  Click on Add to save the settings.

Finally, to the right of the new entry click directly on 'Disabled' then press the key combination to assign to this key binding.  In this case it would be 'Super Key-e'.  The key binding takes effect immediately.  Press the key combination to check the results.  The Nautilus file browser should pop up.

To perform the same process via command line do the following.  These steps assume that there are no other custom key bindings assigned.  If there are, or could be, then an additional step should be taken to list the current custom key binding entries and then add this one with the appropriate number assigned.  Further explanation below.

The following commands must be run as the user.

Command to create the 'custom0' key binding:

gsettings set  org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']"

Command to enter the name of the binding:

gsettings set  org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name 'File Browser'

Command to enter the command to run:

gsettings set  org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command 'nautilus'

Command to enter the key combination that will run the command:

gsettings set  org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding '<Super>s'

The key binding should be in effect after entering the last command.  If it is not working try logging out and back in again.

If other key combinations are wanted, the key names in the standard key bindings can used as an example.  For example, Alt, Ctrl, Shift, Left, Right, Up, Down, Page Up, Page Down, etc.  To use Ctrl+F1 it would be entered '<Ctrl>F1'.


Additional Information

If this is being scripted and there is a possibility that a custom key binding already exists then the script should check the value of the first command above:

gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings

If no custom key bindings exist the value returned will be "@as []".  If one or more exists then it will return what we entered above and may include additional entries similar to this:

['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/']

If an additional key binding needs to be added in addition to what is there then the script will need to write the current value along with a new entry for custom#, in this case custom2.  Then the other commands above would need to run for the same custom#.


Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:7023429
  • Creation Date: 09-Oct-2018
  • Modified Date:03-Mar-2020
    • SUSE Linux Enterprise Desktop
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback@suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Join Our Community

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.


SUSE Customer Support Quick Reference Guide SUSE Technical Support Handbook Update Advisories
Support FAQ

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.

Go to Customer Center