How would I automatically run a script when a new window opens?
Thanks,
Dave
How would I automatically run a script when a new window opens?
Thanks,
Dave
I'd call the script and have it open the new terminal. If you want **any** possible window opening to cause this, that would need to be tied into the window manager and different window managers would have different methods for hooks.
How about just using the vanilla Ubuntu 18.04? I don't even know how to begin to search for that.
Sorry, 18.04 is too new for me and I don't use any DE. I'm a WM-only user but programmed X/Windows applications for about 5 yrs.
Do you want to run 1 script, 1 time?
OR
Do you want to run 1 script, every time a specific window opens?
OR
Do you want to run 1 script, every time **any** window opens?
Hello,
If it is that last option you are after, then the following script would suffice:
What it does is that: there is an infinite loop, and inside that loop the command 'wmctrl -l' runs twice, and which lists the open windows each time. Then it compares the output of the command in these two different instances by checking the number of lines each output has. If the 2nd instance has a greater value than the first (which means that a new window has opened) then the argument of the if statement is fulfilled, and it prints to the screen the happy face: there you can substitute whichever other action you want to take place.Code:while : do wmctrl -l > tmp_wmctrl1.txt sleep 2 wmctrl -l > tmp_wmctrl2.txt tmp1=$(wc -l < tmp_wmctrl1.txt) tmp2=$(wc -l < tmp_wmctrl2.txt) if [ $tmp2 -gt $tmp1 ] then echo ":-)" fi rm tmp_wmctrl1.txt tmp_wmctrl2.txt done
In order to exit from the infinite loop Ctrl+c would end the script.
Regards!
Does wmctrl work on Wayland? Wayland is a relatively new display manager that replaces X11. Wayland was the default for 17.10, but enough other programs weren't ready that 18.04 dropped by to X11 as the default.
A simple count of windows might be fine or it might not. For very little effort, using diff, it would be much better to see if any window processes had changed.
shows that another xterm was started --- the '>' says "new window added" ... a '<' would say one or more was closed.Code:$ diff tmp_wmctrl* 8a9 > 0x0340000f 0 cb35 xterm
So if we grep on '^>' then we'd know that at least 1 new window had showed up.and if the result is larger than zero, a new, additional, window showed up in the last 2 seconds.Code:$ diff tmp_wmctrl* | egrep -c '^>'
There are dead spots with this method. Hooking into the new-window event would solve that. Which is why I'd tie into the window manager and placement hooks that most have. I know mvm, fvwm, and openbox support it, so any compliant WM should do it. What gnome3 (the default DE for stock Ubuntu 18.04) does is a mystery to me, mainly because I've never looked. Gnome3 doesn't work great on low-end systems with minimal GPUs or inside virtual machines, so I won't be using it.
http://openbox.org/wiki/Help:Applica...r-app_settings shows how to control extra stuff for specific applications under openbox. Every WM should have a similar capability. Don't expect any GUI to do this. It will be either config files or dconf or whatever gnome is forcing these days. Binary config files should be outlawed, imho, and are definitely against the core Unix philosophy. Heck, XML is terrible, but at least we can edit settings with a text editor.
https://wiki.gnome.org/Projects/GnomeShell/Extensions might be helpful. IDK.
Ubuntu under Unity had an extension capability using XML files.
I bet someone else can add a little of their knowledge to what Claus7 and I have already and make this even better. None of us is as smart as all of us.
Thank you both! Yes, Claus7 is right - that's what I'm after. I'll try both and see what works better
Here's what ended up working for me (I wanted to force any new windows to raise)
Just wondering, in the case of a program like Pidgin, this method still doesn't work if there's a new message but the window is already existing - is there any way you know of to detect when a panel icon is flashing? When I get a new message on pidgin the icon in the panel flashes (even though the window doesn't raise). There must be some way to detect that and cause the window to raise similar to how this is done above...while :
do
wmctrl -l > /tmp/tmp_wmctrl1.txt
sleep 2
wmctrl -l > /tmp/tmp_wmctrl2.txt
tmp1=$(wc -l < /tmp/tmp_wmctrl1.txt)
tmp2=$(wc -l < /tmp/tmp_wmctrl2.txt)
if [ $tmp2 -gt $tmp1 ]
then
mywin=$(wmctrl -l| wmctrl -l | awk '{ print $1}' | sed '$!d')
echo $mywin
wmctrl -i -a "${mywin}"
fi
rm /tmp/tmp_wmctrl1.txt /tmp/tmp_wmctrl2.txt
done
Thanks,
Dave
A quick google found this gnome3 addon:
https://askubuntu.com/questions/8096...dy-to-use-noti
Is that the end-goal you were trying to achieve?
Actually, that would solve my first question (although I still like being able to do the same thing with a bash script like above)
However that does not solve my second problem: When a Pidgin conversation window is open, but then you bring something to the foreground, then step away from your computer, and while you're away the other person sends another message that window stays in the background (because its not a "new window" its just an "updated window"). Yes, the icon in the panel for Pidgin may change color or even subtly flash a bit, but I want that new posting to raise the window again so I actually see that new post.
So my thought is that if the windows manager (I assume that's what's receiving the "notification" message) is smart enough to flash the little window list icon, there must be a way to detect that change with a script and have the script raise the window. In my case I'm using Tint2, but I've seen that flashing behaviour in other window lists (like cairo dock or docky etc)
Thanks
Bookmarks