Sunday, May 5, 2024
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 2462  / 2 Years ago, thu, april 21, 2022, 7:03:20

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?


More From » shortcut-keys

 Answers
2

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.


[#31309] Friday, April 22, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nerta

Total Points: 414
Total Questions: 103
Total Answers: 97

Location: England
Member since Wed, Apr 19, 2023
1 Year ago
;