2

i can retrieve the list of custom key bindings by:

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

which return something like:

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

But i want to know target key binding via its name? i.e. shutter -> <primary><shift><alt>a

I've figured out one simple but not convenient approach:

gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-  
keybinding:/org/gnome/settin‌​gs-daemon/plugins/media-keys/custom-  
keybindings/custom0/ name
// return the name like `shutter`


gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-  
keybinding:/org/gnome/settin‌​gs-daemon/plugins/media-keys/custom-  
keybindings/custom0/ binding
// return the binding like `<primary><shift><alt>a`

Does any guy know other elegant solutions?

Hizqeel
  • 1,915
  • 28
  • 24
  • 24
e-cloud
  • 269

2 Answers2

4

Small script to find the keybinding by name

The script below will output the keybinding when you run it with the shortcut's name as argument. an example:

$ python3 '/home/jacob/Bureaublad/find_keybinding.py' rename
> '<Primary><Alt>r'

How to set up

  • Copy the script below into an empty file, save it as find_keybinding.py
  • Run it by the command:

    python3 '/path/to/find_keybinding.py' <shortcut_name>
    

Explanation

The information is in the output of

dconf dump /

On the custom keyboard shortcuts, this will output sections like:

[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom9]
binding='<Primary><Alt>r'
command='/home/jacob/.local/share/nautilus/scripts/change_name'
name='rename'

As you can see, we need the line, two lines above

name='rename'

...and so the script outputs that line, stripped from binding=

The script

#!/usr/bin/env python3
import subprocess; import sys
key = "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/"
# read the output from dconf dump /, split into lines
ls = [l for l in subprocess.check_output(["dconf", "dump", key]).decode("utf-8").splitlines()]
# find line corresponding to searched name, print two lines higher
print(ls[ls.index([l for l in ls if "name='"+sys.argv[1] in l][0])-2].replace("binding=", ""))

Additionally

...you could create the directory ~/bin (if it doesn't exist yet) and save the script there without extension, and make it executable. Log out and back in, then simply:

find_keybinding <name> 

will do

Jacob Vlijm
  • 85,475
0

For custom keys try:

for i in $(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings | awk -F"'" '{ for (i=2;i<=NF;i+=2) print $i }'); do
    echo "$(dconf read ${i}binding) $(dconf read ${i}name)"
done

For other keys, grep over the following command:

for schema in $(gsettings list-schemas | grep -E 'keybindings|media-keys')
do
    gsettings list-recursively $schema
done

Check this for more.