gsettingsによるCinnamonのグローバルキーバインディングのカスタマイズ

gsettingsによるCinnamonのグローバルキーバインディングのカスタマイズ

シナモンのいくつかのキーボードショートカットを設定しようとしています。

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"

しかし、これはうまくいきません。 Ubuntu 14.04でシナモン2.4.5を使用しています。

システム環境設定ダイアログボックスでこれを行うことができますが、コマンドライン(自動化のためのより良いオプション)で実行したいと思います。

答え1

私はUbuntu 14.10で作業を始めました。これは、カスタムキーバインディング「スロット」を生成するコマンドです。

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/']"

次に、名前、コマンド、およびバインディング値を設定します。

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"

これをシナモンに関するあなたの質問と比較すると、次のようにフルパスとして追加する各項目を正規化する必要があることが問題になる可能性があります。

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']"

答え2

これは私にとって効果的でした(Debian 9.4のCinnamon 3.2.7)。

   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']"

次のコマンドを実行して、カスタムキーバインディングが設定されていることを確認します。

dconf dump /org/cinnamon/

新しいバインディングは設定GUIでも見ることができます。

答え3

「gsettings」(私の場合は/org/cinnamon/desktop/keybounds/custom-keybinds)を使ってショートカットを設定すると、(直接的な)効果がないことがわかりました。 GUIでいくつかの(関連していない)変更を行うと、ショートカットが実際に更新されます。

私はショートカットキースクリプト(F21とMulti_keyの間)を直接的な効果に変換するPythonプログラム(シナモンGUIベースのコード)を書いています。私はこれを特定のユースケースに合わせて変更することはそれほど難しくないと思います。

#!/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()

答え4

Cinnamon 20.2でこれを行う1行は次のとおりです。

gsettings set org.cinnamon.desktop.interface gtk-key-theme 'Emacs'

関連情報