Atalhos globais personalizados em canela via gsettings

5

Estou tentando configurar alguns atalhos de teclado para a canela:

gsettings set org.cinnamon.desktop.keybindings custom-list \
    "['custom0', \
    'custom1', \
    'custom2', \
    'custom3', \
    'custom4']"

## browser
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name "browser"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command "/home/kaiyin/workspace/bash_scripts/focusRun.sh chromium-browser"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding "['<Primary><Shift><Alt>b']"

## file manager
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ name "fileManager"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ command "/home/kaiyin/workspace/bash_scripts/focusRun.sh nemo"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ binding "<Primary><Shift><Alt>f"
## terminal
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ name "terminal"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ command "/home/kaiyin/workspace/bash_scripts/focusRun.sh gnome-terminal"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ binding "<Primary><Shift><Alt>t"
## gmrun
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/ name "runDialog"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/ command "/home/kaiyin/workspace/bash_scripts/focusRun.sh gmrun"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/ binding "<Primary><Shift><Alt>g"

Mas isso não tem nenhum efeito. Eu estou usando canela 2.4.5 no Ubuntu 14.04.

Eu sei que isso pode ser feito através do diálogo de preferências do sistema, mas eu quero fazê-lo na linha de comando (melhor escolha para automação).

    
por qed 17.12.2014 / 15:43

4 respostas

3

Eu tenho esse trabalho no Ubuntu 14.10 em diante. Este é o comando que irá criar uma chave de ligação personalizada "slot"

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

Você define o nome, o comando e os valores de ligação

gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name "shutter"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command "shutter -s"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding "Print"

gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ name "shutter"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ command "shutter -f"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ binding "<Ctrl>Print"

Se eu compará-lo à sua pergunta sobre canela, acho que o problema é que você precisa qualificar totalmente cada item que está adicionando com o caminho completo, assim:

gsettings set org.cinnamon.desktop.keybindings custom-list \
"['/org/cinnamon/desktop/keybindings/custom0', \
  '/org/cinnamon/desktop/keybindings/custom1', \
  '/org/cinnamon/desktop/keybindings/custom2', \
  '/org/cinnamon/desktop/keybindings/custom3', \
  '/org/cinnamon/desktop/keybindings/custom4']"
    
por 30.04.2015 / 14:29
1

Eu observei que os atalhos de configuração (/ org / canela / desktop / keybindings / custom-keybindings no meu caso) com 'gsettings' não têm um efeito (direto). Somente se eu fizer algumas alterações (mesmo que não relacionadas) na GUI, os atalhos serão realmente atualizados.

Eu escrevi um programa Python (baseado no código da GUI canela) que alterna a tecla de atalho com um script (entre F21 e Multi_key) e tem um efeito direto. Acho que alterá-lo para seu caso de uso específico não deve ser muito difícil.

#!/usr/bin/env python2
import subprocess
from gi.repository import Notify
from gi.repository import Gio, Gdk

CUSTOM_KEYS_PARENT_SCHEMA = "org.cinnamon.desktop.keybindings"
CUSTOM_KEYS_BASENAME = "/org/cinnamon/desktop/keybindings/custom-keybindings"
CUSTOM_KEYS_SCHEMA = "org.cinnamon.desktop.keybindings.custom-keybinding"

curr_shortcut = subprocess.check_output(['gsettings','get', 'org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/', 'binding'])

custom_num=0

def remove_custom():
    keybinding_path='custom0'
    custom_path = CUSTOM_KEYS_BASENAME + "/" + keybinding_path + "/"
    custom_schema = Gio.Settings.new_with_path(CUSTOM_KEYS_SCHEMA, custom_path)
    custom_schema.delay()
    custom_schema.reset("name")
    custom_schema.reset("command")
    custom_schema.reset("binding")
    custom_schema.apply()
    Gio.Settings.sync()

    parent_settings = Gio.Settings(CUSTOM_KEYS_PARENT_SCHEMA)
    array = parent_settings.get_strv("custom-list")

    existing = False
    for entry in array:
        if keybinding_path == entry:
            existing = True
            break
    if existing:
        array.remove(keybinding_path)
        parent_settings.set_strv("custom-list", array)

def add_custom(key):
    parent = Gio.Settings.new(CUSTOM_KEYS_PARENT_SCHEMA)
    array = parent.get_strv("custom-list")

    new_str = "custom" + str(custom_num)
    array.append(new_str)
    parent.set_strv("custom-list", array)
    new_path = CUSTOM_KEYS_BASENAME + "/custom" + str(custom_num) + "/"
    new_schema = Gio.Settings.new_with_path(CUSTOM_KEYS_SCHEMA, new_path)
    new_schema.delay()
    new_schema.set_string("name", 'command_name')
    new_schema.set_string("command",'/path/to/script')
    new_schema.set_strv("binding",[key])
    new_schema.apply()
    Gio.Settings.sync()


if 'Multi_key' in curr_shortcut:
    remove_custom()
    add_custom('F21')
    Notify.init ("Shortcut disabled")
    SC_ON=Notify.Notification.new ("Shortcut","Shortcut disabled","dialog-information")
    SC_ON.set_urgency(0)
    SC_ON.show()
else:
    remove_custom()
    add_custom('Multi_key')
    Notify.init ("Shortcut enabled")
    SC_OFF=Notify.Notification.new ("Shortcut","Shortcut enabled","dialog-information")
    SC_OFF.set_urgency(0)
    SC_OFF.show()
    
por 07.11.2015 / 20:21
1

Isso funciona para mim (Canela 3.2.7 no Debian 9.4):

   gsettings set org.cinnamon.desktop.keybindings custom-list \
        "['custom0', \
        'custom1', \
        'custom2', \
        'custom3', \
        'custom4']"


## browser
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/ name "browser"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/ command "/home/kaiyin/workspace/bash_scripts/focusRun.sh chromium-browser"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/ binding "['<Primary><Shift><Alt>b']"

## file manager
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom1/ name "fileManager"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom1/ command "/home/kaiyin/workspace/bash_scripts/focusRun.sh nemo"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom1/ binding "['<Primary><Shift><Alt>f']"
## terminal
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom2/ name "terminal"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom2/ command "/home/kaiyin/workspace/bash_scripts/focusRun.sh gnome-terminal"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom2/ binding "['<Primary><Shift><Alt>t']"
## gmrun
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom3/ name "runDialog"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom3/ command "/home/kaiyin/workspace/bash_scripts/focusRun.sh gmrun"
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom3/ binding "['<Primary><Shift><Alt>g']"

Verifique se suas atalhos de teclado personalizados estão configuradas executando o seguinte comando:

dconf dump /org/cinnamon/

A nova ligação também pode ser vista nas configurações GUI

    
por 15.03.2018 / 14:19
0

Depois de ter muitos atalhos, é útil colocar tudo dentro de um loop, como no script a seguir:

#!/bin/bash

##############################################################################
###                            CONFIGURATIONS
##############################################################################
name0="browser"
command0="/home/kaiyin/workspace/bash_scripts/focusRun.sh chromium-browser"
binding0="['<Primary><Shift><Alt>b']"

name1="fileManager"
command1="/home/kaiyin/workspace/bash_scripts/focusRun.sh nemo"
binding1="['<Primary><Shift><Alt>f']"

name2="terminal"
command2="/home/kaiyin/workspace/bash_scripts/focusRun.sh gnome-terminal"
binding2="['<Primary><Shift><Alt>t']"

name3="runDialog"
command3="/home/kaiyin/workspace/bash_scripts/focusRun.sh gmrun"
binding3="['<Primary><Shift><Alt>g']"

gsettings set org.cinnamon.desktop.keybindings custom-list \
        "['custom0', \
        'custom1', \
        'custom2', \
        'custom3']"
##############################################################################

let x=0
name=$(echo "name$x")
command_a=$(echo "command$x")
binding=$(echo "binding$x")
while [ "${!name}" ] ; do
   gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom$x/ name "${!name}"
   gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom$x/ command "${!command_a}"
   gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom$x/ binding "${!binding}"
   x=$[$x+1]
   name=$(echo "name$x")
   command_a=$(echo "command$x")
   binding=$(echo "binding$x")
done

Isso torna a organização dos meus atalhos muito mais fácil. Basicamente, você só precisa copiar e colar um novo bloco de namex , commandx e bindingx ( com x sendo o próximo número de atalho ) quando quiser inserir novos atalhos. Por exemplo:

namex="my command"
commandx="path/to/script"
bindingx="['<key><key><key>letter']"

Além disso, insira um novo customx ( novamente com x sendo o próximo número correspondente ) nessa parte do script:

gsettings set org.cinnamon.desktop.keybindings custom-list \
        "['custom0', \
        'custom1', \
        'custom2', \
        'custom3', \
        'customx']"

Depois de executar o script, pode ser necessário pressionar Alt + F2 , digitar r e Entrar para começar a usar o seu novos atalhos ... Não é necessário alterar nada fora da separação CONFIGURATIONS no script ...

    
por 30.06.2018 / 03:05