Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?
share|improve this question

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer
    
Thanks! (I added a link for the shortcut part) –  user138784 May 8 '13 at 13:42
    
Thanks for the edit :) –  thefourtheye May 8 '13 at 13:50

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.

share|improve this answer

For Unity 2D the dconf lines should be

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.