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"

그러나 이것은 효과가 없습니다. 우분투 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에 대해 이 작업을 수행하는 한 줄은 다음과 같습니다.

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

관련 정보