You are not logged in.

#1 2015-06-04 12:49:01

Tristelune
Member
Registered: 2007-10-09
Posts: 86

Refreshing a status bar with a shell script

Hello,

I use the lemonbar to display some informations about my system. The lemonbar
use a shell script to display informations. Sometimes I want to refresh my status bar.
To be brief: is it possible to refresh the status bar without checking for example every 2 seconds with
a "sleep 2" command ?

Let's take an example: with my window manager I switch
from desktop 1 to desktop 2. At the moment I use a sleep command and I refresh the information
every 2 seconds. Is there a way my shell script get notified about the switch from desktop 1 to desktop 2 and can refresh
the information in my status bar ? So it would be not necessary to execute a sleep command every two seconds.

Until now I found nothing. An idea is to react to a keyboard shortcut (the switch from desktop 1 to desktop 2), but
I don't know if it's possible.  Perhaps something with a signal ? I also know some X events are generated by creating or closing windows
for example. I don't know if reacting to X events would be another possibility.

Thank you!

Offline

#2 2015-06-04 14:15:11

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Refreshing a status bar with a shell script

I'm not sure if shell scripts lend themselves particularly well to listening to events.
When I change the sound volume, the new value is saved to a file that is read by the tmux status bar script. The script runs every 15 seconds.
Would something like that be enough?

Offline

#3 2015-06-04 14:28:43

Tristelune
Member
Registered: 2007-10-09
Posts: 86

Re: Refreshing a status bar with a shell script

I'm not sure if it's possible to use something else than a shell script. But if somebody has an idea
with something else, I'm also interested. Perhaps it would be possible to interact with a shell script.

When I read your solution, for me it would be the same as using a "sleep 15" in a shell script. So it's
already what I have at the moment.

Offline

#4 2015-06-04 14:29:38

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,394

Re: Refreshing a status bar with a shell script

Shell scripts are good to react to filesystem events thanks to inotify-wait included in inotify-tools plackage.
But maybe this is more helpful to karol, sorry.


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#5 2015-06-05 10:03:21

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: Refreshing a status bar with a shell script

Whether any hooks or events are exposed for a shell script to listen to is entirely dependent on your window manager. Otherwise you'll have to do what you're doing right now and poll using either wmctrl, xdotool, or something equivalent.

Offline

#6 2015-06-05 13:39:04

esa
Member
Registered: 2011-12-29
Posts: 143
Website

Re: Refreshing a status bar with a shell script

You could try something like this: (untested)

CHECK=$HOME/.cache/x-changed
mkfifo $CHECK
(
	vnr=$XDG_VTNR
	while 	new=$XDG_VTNR 
		[ $vnr = $new ]
	do 	sleep 1
	done
	echo $new > $CHECK 
) &
read RET <$CHECK
rm -f "$CHECK"
echo "New VT: $RET"

hth

Last edited by esa (2015-06-05 13:41:08)


Author of: TUI (Text User Interface for scripts), VHS (Video Handler Script, using ffmpeg) and YASSI (Yet Another Simple Script Installer)

Offline

#7 2015-06-06 06:59:34

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: Refreshing a status bar with a shell script

^You're simply polling in an even more inefficient manner.

Offline

#8 2015-06-06 12:01:48

Tristelune
Member
Registered: 2007-10-09
Posts: 86

Re: Refreshing a status bar with a shell script

Thank you for all your ideas! I will follow the advice of SaintOfCloud. At the moment I have
no window manager, so I have no hooks I can use. I will keep the sleep command.

Offline

#9 2015-06-06 12:12:50

esa
Member
Registered: 2011-12-29
Posts: 143
Website

Re: Refreshing a status bar with a shell script

@ SaintofCloud, how is that?
Its not looping a 15sec sleep, but it would continue as soon the variable changes (actualy the file its content is written).
And it is something to work with/on to get started.

Yeah, a sleep is more efficent that mkfifo... /sarcasm off

Last edited by esa (2015-06-06 12:14:15)


Author of: TUI (Text User Interface for scripts), VHS (Video Handler Script, using ffmpeg) and YASSI (Yet Another Simple Script Installer)

Offline

#10 2015-06-06 12:25:20

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,394

Re: Refreshing a status bar with a shell script

Polling is inefficient, but will work everywhere, while trying to solve a specific problem generally leads to a much more efficient solution; abstraction is not always good...

Eg: if a WM writes the current desktop in a file, then you can just watch that file via inotify and do an event driven action.

As a side note: how do you switch "desktops" without a WM? Was it just an example?

Last edited by kokoko3k (2015-06-06 12:28:06)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#11 2015-06-06 13:02:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: Refreshing a status bar with a shell script

esa wrote:

You could try something like this: (untested)

CHECK=$HOME/.cache/x-changed
mkfifo $CHECK
(
	vnr=$XDG_VTNR
	while 	new=$XDG_VTNR 
		[ $vnr = $new ]
	do 	sleep 1
	done
	echo $new > $CHECK 
) &
read RET <$CHECK
rm -f "$CHECK"
echo "New VT: $RET"

hth

Not only is that inefficient, it doesn't even come close to addressing the question at hand.  XDG_VTNR has nothing to do with the desktop/workspace number within X.  The former is the number of the current VT, the latter is an abstraction created by window managers running on a single VT.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2015-06-07 08:29:33

Tristelune
Member
Registered: 2007-10-09
Posts: 86

Re: Refreshing a status bar with a shell script

kokoko3k wrote:

Eg: if a WM writes the current desktop in a file, then you can just watch that file via inotify and do an event driven action.

I will keep it in mind. I have to check, but it's possible I can use that solution.

kokoko3k wrote:

As a side note: how do you switch "desktops" without a WM? Was it just an example?

Yes, it was an example. If I change in the future I could use the solution for the chosen wm.
But at the moment I can create groups. Each groups get a number and I can raise or hide all applications
in that group. So it's the same problem.

Offline

Board footer

Powered by FluxBB