View Full Version : Bash Script Detect Firefox Window Close
SuperMike
January 12th, 2007, 12:49 AM
From a Bash script, if I load 2 instances of Firefox, and one has a titlebar that has "My Website" in the URL and the other one does not, is there a way to have my Bash script detect when the second window instance (the one that says "My Website") is closed and run some command?
This is important because I need to shutdown 'thttpd' when my XUL application closes (http://www.ubuntuforums.org/showthread.php?t=333862).
ghostdog74
January 12th, 2007, 02:10 AM
just an idea: you can save the PIDs after you launch each of the firefox instances ( to a file maybe?? ) and then have another script to periodically check the current processes against the stored PID values. ..
Engnome
January 12th, 2007, 05:18 AM
Another idea: you can start firefox from a shell script and when firefox exits have your code after it. If you wan't to exit firefox without running your crash code you can try closing the terminal in which the script is running.
SuperMike
January 15th, 2007, 11:05 PM
just an idea: you can save the PIDs after you launch each of the firefox instances ( to a file maybe?? ) and then have another script to periodically check the current processes against the stored PID values. ..
Ghostdog, how does Bash get that PID for me? I guess I never learned that one, although I know quite a lot of Bash.
ghostdog74
January 16th, 2007, 01:18 AM
hi
you can use $! .
for example only: test.sh
#!/bin/bash
while [ 1=1 ];
do
echo "testing"
sleep 5
done
test1.sh :
#!/bin/bash
./test.sh &
echo $!
By invoking test1.sh, you can get the process id of test.sh using $!. Of course,this is just an example.
SuperMike
January 16th, 2007, 02:02 AM
Ah, but this only works if you sent the process to the background with '&', I found. And I can't do that because this is a process I need in the foreground until someone clicks X.
What I need is some kind of X11 command that returns a window list.
SuperMike
January 16th, 2007, 02:20 AM
Oh, I found it!
If you know what the window name is going to be, you can do something like loop with the xwininfo command. For instance:
xwininfo -name 'MyAppWindow' 2>&1 | grep -iv 'No window' | wc -l
returns 0 if 'MyAppWindow' is not open, and returns a non-zero value if it is open.
vBulletin® v3.7.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.