2
2
I am making a bash script for Linux which closes the terminal window if the window loses focus.
On the command line, I was able to do this:
termwin=$(xdotool getactivewindow)
while :
do
if [[ $(xdotool getactivewindow) != $termwin ]]
then
exit
fi
done
It works typed manually into a terminal, but, if I put it into a script, instead of closing the window when focus is lost, the script simply stops. No error or anything, just back to a prompt.
I feel like I'm missing something basic.
EDIT
After reading this...: See here
I tried running this as ". test.sh" rather than "./test.sh" and it worked. The link describes the difference in these methods as running the script as a subprocess or as part of the main process, respectively. Can anyone just explain this, and/or modify the script to run successfully with "./" instead of ". ", in the latter creates issues?
shell script debug is my fun, hold on, I shall try to reproduce. I know xdotool its an automate tool. – Rony – 2012-05-16T16:08:42.110
My idea is a bit off-topic: do you know about "exotic" window managers? E.g. awesome (http://awesome.naquadah.org/) - you can do this or similar functions easily.
– uzsolt – 2012-05-16T16:35:06.073@uzsolt, you are to? if me, I am mainly on awesome wm quite some years and now and all. – Rony – 2012-05-16T16:40:31.243
Yes :) In awesome this is only about 3 lines :) In bash... – uzsolt – 2012-05-16T16:47:19.383
@uzsolt dear, awesome wm has lua, homebrew widgets are candies :), bashlets is another playground :) – Rony – 2012-05-16T16:57:24.530
Please see edit. – Fruckubus Crunt – 2012-05-16T18:02:23.080
Does
./test.sh && exitwork for you? Justexitorexit 0when the condition is met in the script, andexitwill be run in the terminal afterwards. – Daniel Andersson – 2012-05-17T12:00:59.917Oh bloody hell, that's exactly what I had to do. I was too absorbed in the script itself to consider running it like that. – Fruckubus Crunt – 2012-05-17T14:16:54.837
scripting is somehow like building pieces as according to nix philosophy. xdotool is so useful. btw, hug@uzolt – Rony – 2012-05-17T17:35:51.453
@uzsolt 2 lines now ;) cheers. – Rony – 2012-05-17T17:36:53.090
@Rony if you calculate the parts of
whileit will about five lines. In awesome: you call a signal function to unfocus, callc:kill(), typeendand that's all. It's three lines. And you shouldn't run a plus bash script which eats your CPU :) So awesome is the winner ;) – uzsolt – 2012-05-17T17:45:13.393