I'm going to assign this script to a keyboard shortcut so that I can toggle Autohide quickly for Docky.
I'm going to make a second script that switches off Autohide again, and assign a different keyboard shortcut to that.
The reason for closing and relaunching Docky is because Docky doesn't refresh the configuration's settings otherwise. I've written a sudo
command, and I suspect that it won't work.
I want to:
- Do it without any
sudo
command - If it's possible (not important), have one unified script that just toggles between "None" and "Intellihide", so that I don't need to have two seperate keys.
- If possible, have Docky refresh the configuration's values without having to exit and launch again.
#!/bin/bash
gconftool-2 -t string -s /apps/docky-2/Docky/Interface/DockPreferences/Dock1/Autohide "Intellihide" &
sudo killall dockey &
docky
Best Answer
Well, first of all, you are killing the wrong program. Your script has
sudo killall dockey &
but you want to killdocky
, notdockey
. That said, there is absolutely no reason forsudo
,docky
has been started by your user so you can kill it without any special privileges. You also don't need to send it to the background (that's what the&
does).You haven't explained why your script doesn't work but what is probably happening is that you run it and you see nothing happening (please always explain what the symptoms are when asking questions). This is because you are sending the
sudo ...
command to the background with&
.sudo
expects a password:So, when you run it, it will provide a prompt asking for a password. Since you are running it in the background, you will never see that prompt and the script will be stuck, waiting for you to answer.
I don't use
docky
and I have no idea if you can do this without restarting it but restarting seems to be the simplest option. Just change your script to:The
&&
meansAND
, in other words "run the next command only if the previous one was successful". The||
(OR
) is the opposite, "run the next command if the previous one failed. So, the script above will first querygconf
for the current state ofAutohide
. Thegrep
will only be successful if that matchesNone
. If so, it is set toIntellihide
and if not, it is set toNone
Note that
&&
is not the same as&
. The&
sends commands to the background as described above and is not needed unless you want to send something to the background. For more details on the various shell operators, see here.