LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-07-2016, 03:13 PM   #1
linuxlicious
Member
 
Registered: May 2011
Posts: 87

Rep: Reputation: 6
How do I execute a bash script on window events?


I'm not sure if this is the right place for the topic but here goes:
I would like to execute a script that causes a (undecorated/minimal) window border to flash up once when it changes it's state from unfocused to focused. How would I accomplish that? Alternatively, how would I go about executing a similar (modified to change borders to red) when the battery level reaches x%? I have the script figured out, all I need is to use it in a script that detects a window's state and executes the other script when focused.

Alternatively, how would I go about executing a similar script (modified to change borders to red) when the battery level reaches x%?
 
Old 08-08-2016, 12:12 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
this is totally impractical: changing window borders requires interacting with the window manager, most probably changing its theme.
forget it.
it's much more practical to simply pop up a big, fat, red warning when your battery is low.
for that, there's a number of solutions.
 
Old 08-08-2016, 03:17 AM   #3
linuxlicious
Member
 
Registered: May 2011
Posts: 87

Original Poster
Rep: Reputation: 6
Ondoho: I probably should clarify that I use Spectrwm, not a themed window manager like Fluxbox, Gnome or such. Spectrwm doesn't use any themes and decorations, except for a simple border around the windows. Wmctrl is a nifty tool that makes it possible to change the color of the window borders from a script. I wrote such a script, which I shall call flash.sh, and it works as intended - change a window's border to white and back within two seconds. My problem is to figure out how to use flash.sh in a script that detects when a window becomes focused, and executes flash.sh *once*, then continues scanning for windows that change their state to focused.
The idea for a script to change all border colors to red when the laptop battery goes low is just that - another idea and not my main concern.

@ all: Please refrain from posting dismissive and discouraging replies based on your shotgun judgement.

Last edited by linuxlicious; 08-08-2016 at 03:21 AM.
 
Old 08-08-2016, 03:06 PM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by linuxlicious View Post
Ondoho: I probably should clarify that I use Spectrwm, not a themed window manager like Fluxbox, Gnome or such. Spectrwm doesn't use any themes and decorations, except for a simple border around the windows. Wmctrl is a nifty tool that makes it possible to change the color of the window borders from a script. I wrote such a script, which I shall call flash.sh, and it works as intended - change a window's border to white and back within two seconds. My problem is to figure out how to use flash.sh in a script that detects when a window becomes focused, and executes flash.sh *once*, then continues scanning for windows that change their state to focused.
The idea for a script to change all border colors to red when the laptop battery goes low is just that - another idea and not my main concern.

@ all: Please refrain from posting dismissive and discouraging replies based on your shotgun judgement.
well than you found a solution, no?
also, you should have mentioned which wm you use.
i am not familiar with spectrwm, it is possible that it provides changing of border colors on the fly.

@ op: please refrain from wrongly interpreting emotional content into my posts. also please refrain from labeling my choice of phrase with dismissive terminology.
 
Old 08-09-2016, 04:29 PM   #5
linuxlicious
Member
 
Registered: May 2011
Posts: 87

Original Poster
Rep: Reputation: 6
I realize that I may have overreacted, which may be due to built up frustration from past experiences. That being said, what did stop you from asking me about the DE/WM that I use and what I intend to use to accomplish my task? And to tell me to forget about it first thing, without even bothering to ask questions seemed out of line to me. That is what i refer to as a "shotgun judgement".

Back to topic - I only figured out part of the problem, the script that makes the border flash up with the help of wmctrl. What I'm asking help for is to include this script into another script that scans the desktop for any windows that become focused and then executes the other script to make the window border of that focused window flash once. I'm not so experienced in scripting, so I need some help with that.

Last edited by linuxlicious; 08-09-2016 at 04:36 PM.
 
Old 08-09-2016, 06:22 PM   #6
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
BASH is not really event driven so you may have trouble but have a look here:
https://www.semicomplete.com/project...indow_commands

This may have what you need
 
Old 08-14-2016, 04:22 AM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by linuxlicious View Post
I realize that I may have overreacted, which may be due to built up frustration from past experiences.
that's ok, happens to all uf us.

Quote:
That being said, what did stop you from asking me about the DE/WM that I use and what I intend to use to accomplish my task?
it is op's task to provide as much info as possible about their problem, not mine trying to dig out every last bit of relevant info.
and using a non-standard wm like spectrwm is definitely a piece of info one should provide when having a problem with window borders/events.


Quote:
I only figured out part of the problem, the script that makes the border flash up with the help of wmctrl. What I'm asking help for is to include this script into another script that scans the desktop for any windows that become focused and then executes the other script to make the window border of that focused window flash once.
you should look into the man pages of
wmctrl
xprop
xwininfo
xdotool

a short example script that i use to toggle a terminal window with mocp:
Code:
#!/bin/dash

xprop -id  $(xdotool getwindowfocus) | grep -F 'MOC [' && exec xdotool key q
# if the window that currently has focus is mocp (determined by its window title
# - not an elegant solution), use the script to close the window (like pressing q
# on the keyboard) and exit.
wmctrl -R "MOC [" || exec urxvt -e mocp
# otherwise, move an existing mocp terminal window to the current desktop and give
# it focus. OR, failing that, start a new instance.
this is just meant as an example of what one can do with the utilities mentioned above.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute bash script in C waqasdaar Programming 15 10-27-2015 02:54 PM
[SOLVED] execute bash script from pySide script sharky Programming 3 12-23-2013 01:49 PM
Can't execute Bash script. zbe Linux - Software 4 10-17-2008 08:05 AM
bash - how to launch a console window via script and execute commands in it? basd Programming 4 01-26-2008 08:51 PM
Trying to launch a new term window while executing a bash script in that window sfmadmax Linux - Newbie 5 12-09-2007 01:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration