use*_*784 6 python shortcut-keys launcher
我想创建一个键盘快捷键来切换单位启动器的自动隐藏选项。基于如何以编程方式更改启动器隐藏行为的答案,我尝试制作一个 python 脚本来完成这项工作。然后我应该弄清楚如何使用键盘快捷键运行它。
我的脚本如下所示:
#!/bin/python
AUTOHIDE=$(dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode)
if (AUTOHIDE==1):
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 0
else:
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
Run Code Online (Sandbox Code Playgroud)
但是从终端运行脚本(执行 'python scriptname.py' )不起作用。我在 $ 符号处收到“无效语法”错误。
您必须知道我几乎不了解 Python(或一般编写脚本)。(我刚刚花了几个小时在网上搜索帮助和示例)。
所以实际问题:
如果你想用 Pythonic 的方式来做。
#!/bin/python
import subprocess
AUTOHIDE = subprocess.check_output (["/usr/bin/dconf", "read", "/org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode"])
if (AUTOHIDE==1):
subprocess.call (["/usr/bin/dconf", "write", "/org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode", "0"])
else:
subprocess.call (["/usr/bin/dconf", "write", "/org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode", "1"])
Run Code Online (Sandbox Code Playgroud)
您必须通过创建子进程来执行程序。
这是 bash 脚本版本
#!/bin/bash
AUTOHIDE=$(dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode)
if [[ $AUTOHIDE -eq 1 ]]
then
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 0
else
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
fi
Run Code Online (Sandbox Code Playgroud)
可以像这样分配快捷方式。
| 归档时间: |
|
| 查看次数: |
2273 次 |
| 最近记录: |