6

I have created a custom shortcut and bound the shutter -s to it:

enter image description here

Then I tried to find out where this command is stored and checked settings by dconf-editor. But there are no information about the shutter -s bound command and Shift + Print combination:

enter image description here

Thus, the questions:

  1. Where full information about key bindings is stored? Does a way exist to say: this key combination is using this command? For example, I want to see the default screenshot command which is executed on the Print press.
  2. What happens when I press Print key? How this key press achieves a screenshot utility? For example:
    • some tty gets this key
    • GNOME Shell is connected to this tty, so it gets the key as input.
    • then GNOME Shell looks at some database (dconf?) and executes the command bound to the Print key.

I have read similar questions, like

but haven't found an answer to my questions.

MiniMax
  • 159
  • 5
  • did you have a look on https://wiki.ubuntu.com/Keybindings – d1bro Jun 17 '20 at 20:03
  • @db429 Yes. But haven't found answers to my questions there. – MiniMax Jun 17 '20 at 20:08
  • whats the output of bash-autocomplete (double pressing Tabulator) of `gsettings get org.gnome.desktop.wm.keybindings ` – d1bro Jun 17 '20 at 20:15
  • @db429 Have used `gsettings` too. As well as I have looked at `org.gnome.desktop.wm.keybindings` before, through `dconf-editor`. Now, I run `gsettings list-recursively org.gnome.desktop.wm.keybindings | less` and don't see bound commands. – MiniMax Jun 17 '20 at 20:29
  • @db429 `gsettings get org.gnome.desktop.wm.keybindings` and double `Tab` does nothing. – MiniMax Jun 17 '20 at 20:31
  • well for the regular `PrintButton` command on my system I get quiet a lot with `gsettings list-recursively org.gnome.settings-daemon.plugins.media-keys | grep Print` – d1bro Jun 17 '20 at 20:36
  • @db429 1) But these are just action names, aren't? Like `org.gnome.settings-daemon.plugins.media-keys screenshot 'Print'`. I can't launch `screenshot` program from the `bash`. 2) Do you see any custom shortcuts, which mapped to a command with arguments, like `shutter -s`? For example, bind `libreoffice` to some key combination and try to find this shortcut by `gsettings`. – MiniMax Jun 17 '20 at 21:26

2 Answers2

9

Okay, after alot of back-and-forth in the comments, I believe I found the proper way to find the settings:

It is described in https://wiki.ubuntu.com/Keybindings

To find all (system) key bindings:

lets just add all three mentioned commands:

gsettings list-recursively org.gnome.desktop.wm.keybindings ; gsettings list-recursively org.gnome.settings-daemon.plugins.media-keys ; gsettings list-recursively org.gnome.settings-daemon.plugins.power

To find a special key you would pipe the output of each command through grep -i <what you're looking for> (the -i flag is to ignore case of letters) - so if you look for print it would look like this:

gsettings list-recursively org.gnome.desktop.wm.keybindings | grep -i print ; gsettings list-recursively org.gnome.settings-daemon.plugins.media-keys | grep -i print ; gsettings list-recursively org.gnome.settings-daemon.plugins.power | grep -i print

with some bash-magic this clearly could look nicer - but it works ;)

Regarding custom Shortcuts

Custom Shortcuts

Custom shortcuts are stored in dconf using a "relocatable schema". The schema name is "org.gnome.settings-daemon.plugins.media-keys.custom-keybinding". Each custom key binding has three properties: name, command, and binding. Because of the relocatable schema, it is harder to use "gsettings" with custom shortcuts. Here is an example of getting the name of the first custom keybinding:

gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name

Please note, that the last part custom0/refers to the first custom set key binding.

With following command gsettings list-recursively org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ you'll get something like:

org.gnome.settings-daemon.plugins.media-keys.custom-keybinding command 'libreoffice' org.gnome.settings-daemon.plugins.media-keys.custom-keybinding name 'libreoffice' org.gnome.settings-daemon.plugins.media-keys.custom-keybinding binding 'l'

To find the correct entry you might have to increase the number in custom0.

To change e.g. the command use:

gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command '<your command>'

This will also work for name or binding.

To "clear" a custom key binding you could use: gsettings reset-recursively org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/- this would clear the entries inside, yet the entry will still exist in the Gnome-Settings as empty entry, but are 'deactivated', sort of.

How it works with gsettings - the second question: Have a look here: https://developer.gnome.org/gio/stable/GSettings.html

Good Night and Good Luck! ;)

d1bro
  • 2,274
  • 12
  • 23
  • Thanks, now I have found `shutter -s` too. But what about default screenshot application? I can launch it through `Show Application` button by typing `screenshot` in the search bar. So, it looks like a separate program and it should be bound to `Print` key somehow, because when I press `Print` key, the same application is running. My initial purpose was to find the name of this default application and see its command arguments, which is executed on `Print` press. Then I want to launch it by `bash`. – MiniMax Jun 18 '20 at 08:33
  • It seems, that default screenshot application is different from standalone applications like `libreoffice` or `shutter`, maybe it is Gnome extension and can be launched by GUI only. And `screencast` utility the same. – MiniMax Jun 18 '20 at 08:36
  • I looked into the [Gnome Shell source](https://github.com/GNOME/gnome-shell/blob/mainline/src/shell-screenshot.c) and it approves that I have said in the previous comment. This is why I couldn't find a default `screenshot` program - because it is built-in Gnome Shell's functionality. – MiniMax Jun 18 '20 at 10:43
  • @MiniMax "My initial purpose was to find the name of this default application and see its command arguments, which is executed on Print press. Then I want to launch it by bash. " You never wrote that. - I would appreciate if you'd mark this question as solved. – d1bro Jun 18 '20 at 11:02
  • It was written in the 1-st question ;). – MiniMax Jun 18 '20 at 11:24
  • @MiniMax you were asking about key bindings (and used screenshot functionality as exampple) - not about how to use screenshot functionality in a script - or am I mistaken? – d1bro Jun 18 '20 at 11:30
  • Generally, I wanted a way to determine which command is bound to some arbitrary shortcut. Custom and default. To be able to see a command's name and passed options. And we have solved this task: you found out custom shortcuts storage scheme, I found out that default Gnome applications (`screenshot`, `screencast`) are built-in. The second question was auxiliary. So, now I have known what I wanted, thanks for help. – MiniMax Jun 18 '20 at 11:49
0

For custom keybindings the command is:

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}command)"
done

For a specific custom keybinding, 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}command)"
done | grep -i '<Super>A'

For other keybinding, the command is:

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

To find out what a specific key is bound to (not custom commands), run:

for schema in $(gsettings list-schemas | grep -E 'keybindings|media-keys')
do
    gsettings list-recursively $schema 
done | grep -i '<Primary><Super>Up'
Ahmad Ismail
  • 610
  • 9
  • 29