Ubuntu: Keyboard shortcut to toggle auto-hide unity launcher


I would like to create a keyboard shortcut to toggle the auto-hide option for the unit launcher. Based on the answer on How to programmatically change the launcher's hide behaviour I tried to make a python script to do the job. Then I should just figure out how to run that with a keyboard shortcut.

My script looks like this:

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

But running the script from a terminal (doing 'python scriptname.py' ) doesn't work. I get a "invalid syntax" error at $ sign.

You have to know that I have almost no knowledge of python (or writing scripts in general). (I've just spent a few hours searching the web for help and examples).

So the actual questions:

  • What did I do wrong?
  • Did I chose a way to complicated approach for this and how can I do it more easily in that case?


If you want to do it Pythonic way.

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

you have to execute the programs by creating a subprocess.

And this is the bash script version

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

The shortcut can be assigned like this.


One way to do it simply is to create a custom shortcut.

Access System Settings > Keyboard > Shortcuts > Custom shortcuts Then click '+' to add a new shortcut, and in the command box paste:

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

This will create a shortcut for showing the launcher. Now to hide the launcher, you should create another shortcut adding the command:

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

Of course, now you'll have one command for each function, but I put them side by side and find it very intuitive.


For Unity 2D the dconf lines should be


There is also a third mode “Intellihide” whose value is 2.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »