Skip to content

Instantly share code, notes, and snippets.

@discomplex
Last active June 27, 2024 06:45
Show Gist options
  • Save discomplex/8350538 to your computer and use it in GitHub Desktop.
Save discomplex/8350538 to your computer and use it in GitHub Desktop.
CONKY TOGGLE INSTRUCTIONS [turn your conky on/off with a keyboard shortcut]
#CONKY TOGGLE INSTRUCTIONS [turn your conky on/off with a keyboard shortcut]
#Code borrowed from several forums... don't quite rememeber where I found it exactly ;)
#Better used with GNU/Linux CrunchBang <3 #! http://crunchbang.org/donate
---------------------------------------------------------------
#1) Paste the following uncommented line into a blank file:
if pgrep conky; then pkill conky; else conky; fi
#2)Name the file as something like:
conkytoggle.sh
#3)Make the file Executable:
chmod +x conkytoggle.sh
#4)Copy the file into your Home folder (~/ ...or any other folder, like ~/bin for example)
#5)Assign a Shortcut to this file on your *RC.xml file, ex:
<keybind key="W-c">
<action name="Execute">
<startupnotify>
<enabled>true</enabled>
<name>toggle conky</name>
</startupnotify>
<command>~/conkytoggle.sh</command>
</action>
</keybind>
#6)It should work when you press W + c... but you never know!
@adamgiacomelli
Copy link

To avoid pgrep grabbing the script itself rather than conky (e.g. if its name includes conky) -x should be added to exactly match the pattern.
An updated version would look like:

#!/bin/sh

if pgrep -x conky > /dev/null; then
    # Kill the conky process
    echo "Stopping conky..."
    pkill -x conky
else
    # Start conky
    echo "Starting conky..."
    conky &
fi

see https://linux.die.net/man/1/pgrep

-x
    Only match processes whose name (or command line if -f is specified) exactly match the pattern. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment