SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2015-03-01 11:32:44

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Conky Switcher (Pipe Menu)

cd ~/bin && wget -N https://raw.githubusercontent.com/woodape/bl-switcher/master/bl-conky-switcher.py && chmod +x bl-conky-switcher.py

Last edited by kbmonkey (2015-03-18 06:24:20)

Offline

Help fund CrunchBang, donate to the project!

#2 2015-03-01 11:43:17

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Re: Conky Switcher (Pipe Menu)

    <item label="foo">
        <action name="Execute">
            <command>
               killall conky &amp;&amp; conky -c "/home/kbmonkey/.conky/foo/foo.conky"
            </command>
        </action>
    </item>

Offline

#3 2015-03-01 11:55:50

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

Very cool! For your technical thing, have you tried issuing the command through a shell? Something like:

sh -c "killall conky && conky -c '/home/kbmonkey/.conky/foo/foo.conky'"

Offline

#4 2015-03-01 13:03:59

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: Conky Switcher (Pipe Menu)

Try this:

killall -SIGUSR1 conky -c /home/kbmonkey/.conky/foo/foo.conky

I'm in Windows 10 ATM so I can't check this...

EDIT: No, doesn't work with the `-c` flag hmm

Last edited by Head_on_a_Stick (2015-03-01 13:35:03)

Offline

#5 2015-03-01 17:01:03

PackRat
#! Die Hard
From: USA
Registered: 2011-03-03
Posts: 1,572

Re: Conky Switcher (Pipe Menu)

sh -c "killall conky && conky -c '/home/kbmonkey/.conky/foo/foo.conky'"

"It does not require many words to speak the truth." - Chief Joseph, Nez Perce tribe

Offline

#6 2015-03-01 17:24:56

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Re: Conky Switcher (Pipe Menu)

@woodape, pushing the command through sh -c did not work.

@PackRat, multiple Execute actions do not work for some reason.

Thanks both for the good ideas though. Maybe it has to do with how openbox executes external commands, and using && breaks it.

Offline

#7 2015-03-01 18:55:08

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: Conky Switcher (Pipe Menu)

In menu.xml you chain commands by separating them with a semi-colon. And you need to change eg "&" to "&amp"

Last edited by damo (2015-03-01 18:56:49)

Offline

#8 2015-03-01 20:14:51

tknomanzr
#! Die Hard
From: Heavener, OK
Registered: 2014-12-09
Posts: 777

Re: Conky Switcher (Pipe Menu)

I use simple shell scripts for this sort of thing. That is all tint2restart and conkywonky are after all.

Offline

#9 2015-03-03 07:37:19

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Re: Conky Switcher (Pipe Menu)

@damo I tried escaping the text to &amp; without luck, but will try using semi-colons between commands. Cheers!

@tknomanzr, it certainly is. And now there is a graphical menu too! Everybody loves to have choices  devil

Offline

#10 2015-03-11 22:59:25

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

Hey @kbmonkey - @detinith and I have taken your GPL to heart and modified your code a bit more to our liking, and we probably have solved the first todo sufficiently, and put you on the road to the second.

We made it so all *.conky files must be in directories in the ~/.conky folder and the folder is selected in the pipemenu, not the *.conky file. This allows all *.conky files in the selected folder to be launched, not just one, so the script can support multi-conky setups like many people have. The code for that is just replacing the bottom part of your code from the last if statement down with the following:

    if len(sys.argv) == 1:
        CONFIGFILES = list(grabConfigFiles(CONFIGSHOME))
        CONFIGDIRS = []
        for file in CONFIGFILES:
            CONFIGDIRS.append(os.path.dirname(file))
        CONFIGDIRS = list(set(CONFIGDIRS))
        CONFIGDIRS.sort()
        print('<openbox_pipe_menu>')
        for configdir in CONFIGDIRS:
            print(buildConkyMenuItem(configdir))
        print('</openbox_pipe_menu>')
    else:
        configFiles = list(grabConfigFiles(sys.argv[1]))
        subprocess.call(['killall', 'conky'])
        file = open(os.path.join(CONFIGSHOME,'session.log'),"w")
        file.close()
        file = open(os.path.join(CONFIGSHOME,'session.log'),"a")
        for configFile in configFiles:
            subprocess.Popen(['conky','-q','-c', configFile])
            file.write(configFile + "\n")
        file.close()

The file writing bit there stores the full paths of the config files of the selected conky setup in a file called 'session.log' in the ~/.conky folder. This file can then be parsed by a simple bash script called from the Openbox autostart script to launch all the conky configs in this file:

#!/bin/bash
while read config ; do
    conky -q -c "$config" &
    sleep 1s
done < "$HOME/.conky/session.log"
exit 0

I suppose it could be translated into python, but I'm much more fluent in bash and at 6 lines, this is pretty parsimonious.

In any case, I'd just like to reiterate that I'm loving this script you put together. It allows me to have much more organized sets of conkies that I can quickly switch between.  smile

Offline

#11 2015-03-12 10:57:08

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Re: Conky Switcher (Pipe Menu)

@woodape and @detinith that is a great change, particularly how it supports multiple conky scripts across sessions - thank you! I am eager to try it out later at home  smile

Offline

#12 2015-03-12 21:22:11

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

{standing in the corner ... interested ... have to go out ... thinking I'll have comments later}  wink

@ kbmonkey - well done!  Good idea

Offline

#13 2015-03-13 06:32:41

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Re: Conky Switcher (Pipe Menu)

Your changes work wonderfully @woodape and @detinith thank you. I updated the original post and included the shell script to resume the session from autostart. I was wondering how to support multiple conky's and your idea just seems so elegant and simple  cool

Offline

#14 2015-03-13 12:27:38

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

pkill -xf "conky -c ~/.conkyrc"

Last edited by Sector11 (2015-03-13 12:33:25)

Offline

#15 2015-03-13 13:10:01

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Re: Conky Switcher (Pipe Menu)

What an interesting idea, thank you Sector11 - adding conky's to the list of running instances for combine layouts? hmmm, I will think on this while I drive home from work...

In the mean time I am imagining adding two menu items, to kill all conky's and another toggle-option that determines if running instances are killed first when a new conky is run.

This way you can click through multiple configs in any order to combine layouts (but would require some extra logic to preserve any session.log entries)

Conky Switcher
--------------> Config 1
                Config 2
                Config 3
                --------
                kill all
                [x] Combine Mode

I will see if I can steal some time this weekend to play around with this idea - will be out of my home-town until Sunday.  angel

Last edited by kbmonkey (2015-03-13 13:11:42)

Offline

#16 2015-03-13 20:09:07

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

Offline

#17 2015-03-13 20:49:06

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

import fileinput

Last edited by woodape (2015-03-14 07:52:29)

Offline

#18 2015-03-13 20:57:22

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

Whoops! That new killall item should be the following:

Edit: have just updated the code in the above...should have done that to begin with glasses

Last edited by woodape (2015-03-13 20:58:56)

Offline

#19 2015-03-13 22:20:49

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

Offline

#20 2015-03-14 03:25:52

smacz
#! Junkie
Registered: 2014-12-09
Posts: 250

Re: Conky Switcher (Pipe Menu)

Load [Top Right]
Load [Top Line]
Kill [Top Left]
Kill [Bottom Right]
Load [Bottom Left]
-------------------------
Killall

Last edited by smacz (2015-03-14 07:11:20)

Offline

#21 2015-03-14 07:06:29

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

woodape@treebox:~/.conky$ tree --dirsfirst
.
├── Archive
│   ├── chron.conky
│   └── chronograph-12.lua
├── Bottom Left
│   └── chron.conkyrc
├── Bottom Right
│   └── chron.conkyrc
├── Top Left
│   └── chron.conkyrc
├── Top Line
│   └── chron.conkyrc
├── Top Right
│   └── chron.conkyrc
├── conky_restore
└── session.log

6 directories, 9 files

Offline

#22 2015-03-14 07:08:57

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

Last edited by woodape (2015-03-14 09:13:10)

Offline

#23 2015-03-14 07:26:51

smacz
#! Junkie
Registered: 2014-12-09
Posts: 250

Re: Conky Switcher (Pipe Menu)

@woodape I only questioned the python 2 vs 3 because I had never seen the "%(variable)s" notation before. That's really handy. I'm still also trying to get the script working despite eliminating the space. I've ran the script from the command line, and I don't visually see anything out of the ordinary in stdout, but obmenu gives me a dialog box saying that there's 'Invalid Output from pipe-menu'. Any idea if I can get a more descriptive error anywhere? ".xsession-errors" is not being helpful anymore.

The output that you posted looks like exactly what was being discussed. I'm excited to get it working!

EDIT: Running it on the command line, I realized that I'm not sure what all the arguments are meant to be. What should the index look like for the `sys.argv` list? As far as I gather it should be:

[bl-conky-switcher-pipemenu.py, {kill | add}, ${conky}]

Because

./bl-conky-switcher-pipemenu.py add /home/smacz42/.conky/bl-right

works for me from the command line. So the script itself is solid. And if I move the .conky/ directory to something else, the warning will pop up for me. I'll keep checking my implementation. I never though copying and pasting was so error-prone!

Last edited by smacz (2015-03-14 07:55:22)

Offline

#24 2015-03-14 07:52:09

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

@smacz - I found the little error in the code I posted. I must have corrected it on my machine and not in the post. The menu generator is missing an end "</menu>" tag. so it should be:

menuFormat = """
    <menu id="conky - %(label)s" label="%(label)s">
        <item label="Add Conky">
            <action name="Execute">
                <command>
                    %(thisexecutable)s 'add' "%(configpath)s"
                </command>
            </action>
        </item>
        <item label="Remove Conky">
            <action name="Execute">
                <command>
                    %(thisexecutable)s 'kill' "%(configpath)s"
                </command>
            </action>
        </item>
    </menu>
    """

I'll change this is my block now. I don't really know where to get more descriptive errors. Though since this is a *.xml format you could redirect the output to a file and get vim or some other program to do syntax checking for you.

I've also never seen the "%(variable)" notation before, but I'm really not that fluent with python, I rely on stackexchange.com to tell me the little bits I need to know.

Last edited by woodape (2015-03-14 07:56:57)

Offline

Help fund CrunchBang, donate to the project!

#25 2015-03-14 08:02:05

smacz
#! Junkie
Registered: 2014-12-09
Posts: 250

Re: Conky Switcher (Pipe Menu)

Ninja'd!!! I just found it but you beat me to the punch. Although honestly I should have seen that for myself a long time ago... Thank you.

EDIT: I haven't been able to make anything useable thus far, and I have to go pass out for now, but I was working on something similar before this thread and had stumbled across this function to retrieve information about running processes from the /proc filesystem:

import os
import re

pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]

processes = []

for pid in pids:
  try:
    procs = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
    # "% conky" can be whatever term we need to search for
    if re.search("%s" % conky, procs):
      processes.append(procs)
  except IOError: # proc has already terminated
    continue

Hopefully that can help when it comes to determining how we might go about annotating the conkys that can be loaded versus the ones that can be killed by providing a list of running ones.

Last edited by smacz (2015-03-14 09:32:53)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo