Window focus event for shell scripts.

Hacking is always fun. That’s why I always lose focus on everything one interesting hack. That’s why I spent whole last night trying to figure out how to mimic Window focus event in a shell script. Though this is completely new to me, you maybe very much comfortable with implementing it :) . If so please let me know in comments.

Anyway here is my story.

I found this nice command line IM client called centerIM (Thanx @chathuraw for info). Once I got it set up I was just scanning on it’s documentation page & came across this interesting part “External actions & auto-responses“. I wrote a script right away for GUI notifications, inspired by notify.pl script for irssi. Here is the script if you are interested.

Since the load of IM messages was very high at a time & It was useless when the terminal window with centerIM was already focused (which means I’m chatting on centerIM) I was thinking of getting notifications only when centerIM window is not in focus. Few Google searches lead me to very limited resources & I chose xwininfo & xdpyinfo commands for my work.

Workaround: I’m using gnome for now & so gnome-terminal as my terminal emulator. I had to set edit > profilepreferences > Title & command option to keep initial title, in order to have “Terminal” as the terminal window name all the time.

And ran xininfo to get following output.


chanux@nim:~$ xwininfo -name Terminal

xwininfo: Window id: 0x3800003 "Terminal"

 Absolute upper-left X:  0
 Absolute upper-left Y:  52
 Relative upper-left X:  0
 Relative upper-left Y:  27
 Width: 1280
 Height: 691
 Depth: 24
 Visual Class: TrueColor
 Border width: 0
 Class: InputOutput
 Colormap: 0x20 (installed)
 Bit Gravity State: NorthWestGravity
 Window Gravity State: NorthWestGravity
 Backing Store State: NotUseful
 Save Under State: no
 Map State: IsViewable
 Override Redirect State: no
 Corners:  +0+52  -0+52  -0-25  +0-25
 -geometry 156x37+0+25

This can be used to get the window id of the windw which runs the script.

Then I can find the focused window at the moment as following.


chanux@nim:~$ xdpyinfo |grep focus
focus:  window 0x3800004, revert to Parent

I fetched the window IDs with a little bit more work.

Anyway the problem I had is that, I get 0×3800003 (at this example) or likewise for the Terminal window id & even when the Terminal id is focused I get 0×3800004 as the focused window id. Yes I know with some more work I can manage to handle that & come to a point that I can compare those window Ids to check for the focused window. But I reall like to know why that difference come up. Anyone have an explanantion? Or anyone like to mess with this?

Following is the way I fetched window ids from above outputs


chanux@nim:~$ xwininfo -name "Terminal" | grep xwininfo | cut -d " " -f 4
0x3800003
chanux@nim:~$ xdpyinfo | grep focus | cut -d " " -f 4 | sed s/,//
0x3800004

Join me in MJ ass kissers club.

OK, There’s one now. wait.. wait… it was not me. That sage girl defined the club. First of all let’s see who are already in.

The Way you make me feel | How I see it
Michael Jackson and Me | Landon Lanka and Drums
A Legend | A heart on a sleeve
The way you make me feel | delilah says
There will never be another you, MJ | Jus Chillin’
MJ’s gone :( | A glimpse of lady devine
What’s your fav MJ? | Chaar~Max 2.0
Singer Michael Jackson dies at 50 | Gossip Lanka
‘King of Pop’ Michael Jackson dies at age 50 | City Hits
The Six List – Tribute to “The King of Pop…” | Untitled
So, about MJ | The Abyss

Update: Here is a comprehensive list of blog posts on MJ’s death on achcharu.org. (thanx drac for the link) Most of the writers should include the club. Now I really love to be in this club :P .

Dropped in happily:

Doesn’t matter if you are black or white. | Bumble for PM

So this is all I found on a kottu search (query:MJ Michael). If I’ve missed any of you please let me know. And if you think you don’t match the club since you are not upset of MJ’s death, ping me I’ll remove you from the list.

11 posts (edit : at the beginning it was), written by people who are shocked by the death of MJ. I just feel like that’s not enough. I too join the club.

Yesterday I woke up to the news ‘MJ died’ on Fox news or something. First thing I did was switching on my laptop & rushing to the interwebz. My twitter feed didn’t have much info but Twitter search kinda confirmed that I should start to feel upset. Not that I’m a big fan. But I dunno why the hell I feel so bad that MJ is not any more. I can remember I grew up listening to him. Heard those strange stories about him. My uncle had few albums of MJ which I still can remember the cover art of.

I was upset when people call him a child molester. But I just didn’t give a shit. Yeah that’s my kind, “Just don’t give a shit”. But I can’t stop feeling upset of MJ. Maybe that’s because he was a legend, an icon & still he went away that way. Maybe I’m not upset about MJ but the universal truth, “it all comes to an end”. MJ’s death just make it a bit clear I guess. well… I dunno.

So I hope I’m in the club, *drumroll* “MJ ass kissers club”.

Damn it feels so cool here. But I wonder why the “sage girl” is upset about our feelings. We putting on feelings on our blogs which are public, which unfortunately are on kottu, which is sage girl’s personal feed reader. Indi… hey buddy please kick me off. Please do that. Sage girl is upset about what we write. And hope others in the club will also get their blogs out of kottu, just to make sage girls reading experience a bit better.

And by the way guys, sage girl also says like this.

“My blog is mine. I never invited you to read it.” (source. And it’s not the first one)

Now tell me why you put your blog on Kottu? isn’t it kind of an innocent invitation to other kottu readers to read this? Well.. I like when people read my posts, kottu people too. But unlike sage girl *I don’t write for Kottu*. So just think why we should get labeled as ‘ass kissers’ for being on Kottu? (and stuffing sage girls good read heaven a hell).

Anyway sage girl always manages to eclipse her own thoughts by her own thoughts. Sounds freaky but that’s the way it is. Defending her own false facts with another bunch of false facts. What got pissed me off of is aiming bloggers who are free to write & free to be on any social aggregator as long as they don’t harm the community or any terms set by the aggregator so badly. And this not the fucking first time.

I know I’m trying to put too much light on a small bug. But I don’t want to see this happened again & again.

PS: I was trying very hard to not use any offensive words (ex: fuck, fucking, shit) coz I’m practicung to reduce the usage :-S.

Make Twitterfox use the URL shortner that You want.

I found This nice howto via @meaningful. Looks like the howto is for older version of Twitterfox. Here goes how to do it on Twitterfox 1.8.1 (The version I use right now)

And I recommend you to update to Twitterfox 1.8.1 coz it’s really improved.

First go here:

<path to your Firefox profile directory>/extensions/twitternotifier@naan.net/chrome

[you'll learn howto find your Firefox profile directory (AKA folder) here. There are too many operating systems. I can't cover them all :P   ]

There is a file called TwitterFox.jar

Open it & go in to directory called content. There you’ll find the file called twitterfox.js, you better open it with a text editor.

In the top region of the file you’ll find TINYURL_CREATE_API variable. it is set to use tinyurl api by default. I edited it to use my favorite URL shortnet tr.im by editing it to look like this.

var TINYURL_CREATE_API = “http://tr.im/api/trim_simple?url=”;

You can repalce http://tr.im/api/trim_simple?url= with the API of your favorite URL shortner.

You need to restart Firefox for the changes to be effective.

Hope it works ;) . Anything not clear? Just ask in comments.

PS: You may not like to try this but I don’t give a shit :P .

What I learned from past 12+ hours of compiling tamasha?

I was compiling Qt from source. And had loads of issues. This is what I learned after all.

1. Errors are chances to learn.

2. Never copy paste command / code blindly from somewhere on the Internet.

Even if it’s very trustworthy source. Copy paste process might produce errors to ruin your day :) . Check the code for yourself. Especially beware of commands/codes looking ‘obvious’.

3. When you ask for help give the helper everything.

Not what YOU THINK is useful.
When you get troubles your sanity shakes a bit :) .

4. It’s always helpful.. well.. to sleep.

http://news.bbc.co.uk/2/hi/health/8090730.stm . They are right. Believe me.

5. Sometimes it makes sense to “start it all over again”.

Hunting errors one buy one might probably be a Goose chase.

6. It’s always good to have nice & helpful friends & community around :) .

7. You should never trust a machine.

8. You better have good Internet.

I’m not talking about these guys. ?

Happy Birthday SinhalenFOSS!

SinhalenFOSS, Sri Lankas very first tech related podcast, the podcast that I proudly feature in, turned one year yesterday(9th April 2009). We didn’t have big plans for the day but it was truly a big milestone for me. I’m sure the story is same for the other two co-hosts Bud (geekaholic) & Seejay.

We had the episode 21 recorded on last sunday (5th April 2009) but due to my busy schedule I couldn’t finish editing & upload it. Finally there was a hope for uploading it on SinhalenFOSS birthday. But I’m really sorry that I couldn’t make it on time since my father was sick & I had to go to the doc with him. Added to that, I couldn’t stay up all night & finish it off since I was tired of fairly a long journy. Actually I tried to stay awake but failed. However my computer stood awake when I find it on my bed in mid night (Poor thing!).

Anyway I’ll try to finish things up & put the final product in our loving listeners hands As Soon As Possible!. The bits are running in to interwebz right now :) .

It was a pleasant year passed giving me lots of experience, introducing lots of nice people to me, taking my life to another level & best of all, making me very happy for being a part of. It’s all thanks to you dear SinhalenFOSS, I really love you. Wishing you a very happy birthday!

Update: SinhalenFOSS episode 21 is on interwebz now :)