用于切换自动隐藏统一启动器的键盘快捷键

我想创建一个键盘快捷键来切换单元启动器的自动隐藏选项。 基于如何以编程方式更改启动器的隐藏行为的答案,我试图制作一个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 

但是从终端运行脚本(执行’python scriptname.py’)不起作用。 我在$ sign处收到“无效语法”错误。

你必须知道我几乎不了解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"]) 

你必须通过创建子进程来执行程序。

这是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 

可以像这样分配快捷方式。

一种方法就是创建自定义快捷方式。

访问系统设置>键盘>快捷方式>自定义快捷方式然后单击“+”添加新的快捷方式,并在命令框中粘贴:

 dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 0 

这将创建一个显示启动器的快捷方式。 现在要隐藏启动器,您应该创建另一个添加命令的快捷方式:

 dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1 

当然,现在你将为每个函数配备一个命令,但我将它们并排放置并发现它非常直观。

对于Unity 2D,dconf行应该是

 /com/canonical/unity-2d/launcher/hide-mode 

还有第三种模式“Intellihide”,其值为2。