[Solved] Toggle conky window show/hide awesome wm - can script with keybinding work?

ebscriptwalker

New Member
Joined
Jul 9, 2019
Messages
5
Reaction score
1
Credits
0
First time posting, and still a linux novice in many ways. I am using conky to display gcalcli on my desktop, and would like to be able to invoke/show, hide the conky window using a keybinding in awesome wm. Any suggestions would be greatly appreciated.
 


As far as I know Terminal conky to turn it on then terminal kill all conky to turn off.
 
Thanks for the response. Unfortunately I am aware of ths method, however I would prefer not to use it because I am running two instances of conky (one for my system monitor, the other I am using to display my google calander via gcalcli ) and I would prefer not to actually kill the process. instead I would like to maybe keep it running in the background, and more hide it. and return it to the screen via a keybinding. It seems as though awesomewm may be capable of doing such a thing. But I am unsure of how exactly. I might be able to kill the process by process id, but I im not sure how I would do such a thing from a keybinding
 
;)G'day @ebscriptwalker and welcome to linux.org :), and G'day Tobey if you are still around (love that avatar).

Mate I reckon a part of your userid is likely a part of the answer, and that is script.

If you like, I can move this Thread to Command Line, where scripting answers are provided.

I did a brief Google search under

linux run multiple conky

and found this

https://www.omgubuntu.co.uk/2016/02/run-multiple-conky-scripts-same-session

Now I reckon you would likely write a script and make it an executable .sh file and have the keybinding call upon that file for the start stop process of the one identified as not always necessary.

Have a think about it, and if you want the move, I can perform a little wizardry, and also invoke the names of two of our better scriptwriters and see if they have ideas.

Cheers

Chris Turner
wizardfromoz
 
Thank you for your help. If you think that the command line section would be a better place for this topic I would much appreciatethe move.
 
"Walker" - I have added a little to the Title to help others zero in.

Cheers

Wizard
 
Set up a script which uses pgrep to check for all running instances of conky - then use awk to filter out results that contain the name of the .conkyrc file you use to start the conky instance you want to toggle and then print/store any returned PIDS to a variable.

If the variable is empty:
- Start conky in the background using the appropriate .conkyrc file.
If it contains one or more PIDs:
- kill all of the PIDs stored in the variable.

That should effectively toggle an instance of conky which has been started using a particular .conkyrc file.

Which completely off the top of my head - and completely untested would look something like this:
toggleconky.sh
Bash:
#!/usr/bin/env bash

# Try to get a list of PIDs for appropriate conky's
runningConkys=$(pgrep -a conky | awk '/nameofconkyrc/{print $1}')

# if runningConkys is empty
if [[ -z "$runningConkys" ]]; then
    # start conky
    conky -q -c /path/to/nameofconkyrc &
else #not empty
    #Kill all of the PIDs listed in $runningConkys
    echo "$runningConkys" | xargs -n 1 kill -15
fi

Extremely important:
Before attempting to run the above script - you need to do a couple of things.
- In the awk - replace nameofconkyrc with the file-name of the .conkyrc file for the conky you want to toggle. (No path - just the file-name for the rc file)

- Where we start the conky - replace /path/to/nameofconkyrc with the full path and filename of the .conkyrc for the conky you want to toggle.

Then you simply make the script executable and assign a keybind to run the script in your DE/WM and that's it!
That should allow you to toggle your extra conky instance.


Again - I've written this completely off the top of my head, so this hasn't been tested. But I don't see any reason why it wouldn't work.
If it's not completely correct - it'll at least be close!

[edit]
I'll have a little play with this when I get home from work this evening and see if it works. I might have some uses for a script like this myself.
[/edit]
 
Last edited:
Thank you tons Jas, works perfectly very nice solution, not nearly as convaluded as I thought it would be. Thank you also wizard you were extremely helpful. H Just wondering why you used "#!/usr/bin/env bash" as apposed to the #!/binbash , is that just your path to bash shell or is there another reason? Also back to wizard is there a specific way for me to mark as solved or just edit the title?
 
G'day Walker ... Jas is The Man with scripting, we also have a newer Member, Ken Jackson very good, and our Admin, Rob, likewise so we are well looked after :)

Jas explains your question here a few weeks ago

https://www.linux.org/threads/clear-steps-to-make-an-sh-file-executable.23782/post-70750

I think it is the 2nd Spoiler in the Post I have linked with. Spoiler is a toggle, click to open, click to close.

Solved as you have just done is fine. We leave Threads open in case someone else with a similar problem wanders in, or the OP (Original Poster) has a recurrence of the problem or similar, or news.

Friday in Oz folks, so

Avagudweegend.

Wiz
 
Happy to have helped!

To save trawling through my other thread. The reason I used /usr/bin/env bash is because bash isn't necessarily always going to be in the same place on every distro. Using env we can avoid having a hard coded path to bash in our script. Instead the path to bash can be deduced from the users environment.
 
Thank you tons Jas, works perfectly very nice solution, not nearly as convaluded as I thought it would be. Thank you also wizard you were extremely helpful. H Just wondering why you used "#!/usr/bin/env bash" as apposed to the #!/binbash , is that just your path to bash shell or is there another reason? Also back to wizard is there a specific way for me to mark as solved or just edit the title?
Hello from 2020, can you write video of this effect?
 

Members online


Latest posts

Top