Вопрос аналогичен этому: ярлык клавиатуры для открытия файлового менеджера Ubuntu?
За исключением того, что я хотел бы знать, можно ли это сделать через командную строку, вместо GUI.
Задача состоит в том, чтобы установить ярлык /home/usr на super+E на недавно установленном Ubuntu.
Причиной этого является то, что больно настраивать многие машины через графический интерфейс. В качестве последнего средства всегда можно моделировать мышь и клавиатуру для автоматизации. Однако для мешков вопроса, предполагая, что это не вариант.
Код похож на этот: Как установить пользовательские сочетания клавиш из терминала? За исключением того, что он исправляет ошибку, когда нет настраиваемых ключей. Возможно, кто-то с priviledge может смешать ответы и удалить этот.
Часть Python:
#!/usr/bin/env python3
import subprocess
import sys
# defining keys & strings to be used
key = "org.gnome.settings-daemon.plugins.media-keys custom-keybindings"
subkey1 = key.replace(" ", ".")[:-1]+":"
item_s = "/"+key.replace(" ", "/").replace(".", "/")+"/"
firstname = "custom"
# get the current list of custom shortcuts
get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")
# No custom keys
if get("gsettings get "+key) == "@as []\n":
n = 0
current = list()
new = item_s+firstname+str(n)+"/"
# Found custom keys
else:
current = eval(get("gsettings get "+key))
# make sure the additional keybinding mention is no duplicate
n = 1
while True:
new = item_s+firstname+str(n)+"/"
if new in current:
n = n+1
else:
break
# add the new keybinding to the list
current.append(new)
# create the shortcut, set the name, command and shortcut key
cmd0 = 'gsettings set '+key+' "'+str(current)+'"'
cmd1 = 'gsettings set '+subkey1+new+" name '"+sys.argv[1]+"'"
cmd2 = 'gsettings set '+subkey1+new+" command '"+sys.argv[2]+"'"
cmd3 = 'gsettings set '+subkey1+new+" binding '"+sys.argv[3]+"'"
for cmd in [cmd0, cmd1, cmd2, cmd3]:
subprocess.call(["/bin/bash", "-c", cmd])
Вызвать сценарий выше в командной строке:
python3 /path/to/script.py 'home folder' 'nautilus /home/user' '<Super>e'
Код похож на этот: Как установить пользовательские сочетания клавиш из терминала? За исключением того, что он исправляет ошибку, когда нет настраиваемых ключей. Возможно, кто-то с priviledge может смешать ответы и удалить этот.
Часть Python:
#!/usr/bin/env python3
import subprocess
import sys
# defining keys & strings to be used
key = "org.gnome.settings-daemon.plugins.media-keys custom-keybindings"
subkey1 = key.replace(" ", ".")[:-1]+":"
item_s = "/"+key.replace(" ", "/").replace(".", "/")+"/"
firstname = "custom"
# get the current list of custom shortcuts
get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")
# No custom keys
if get("gsettings get "+key) == "@as []\n":
n = 0
current = list()
new = item_s+firstname+str(n)+"/"
# Found custom keys
else:
current = eval(get("gsettings get "+key))
# make sure the additional keybinding mention is no duplicate
n = 1
while True:
new = item_s+firstname+str(n)+"/"
if new in current:
n = n+1
else:
break
# add the new keybinding to the list
current.append(new)
# create the shortcut, set the name, command and shortcut key
cmd0 = 'gsettings set '+key+' "'+str(current)+'"'
cmd1 = 'gsettings set '+subkey1+new+" name '"+sys.argv[1]+"'"
cmd2 = 'gsettings set '+subkey1+new+" command '"+sys.argv[2]+"'"
cmd3 = 'gsettings set '+subkey1+new+" binding '"+sys.argv[3]+"'"
for cmd in [cmd0, cmd1, cmd2, cmd3]:
subprocess.call(["/bin/bash", "-c", cmd])
Вызвать сценарий выше в командной строке:
python3 /path/to/script.py 'home folder' 'nautilus /home/user' '<Super>e'