Question

I'm trying to write a python program that checks every X seconds if the 'window title' for 'last.fm' (http://www.last.fm/download) changed, if it did (or it's the first time I run the program) it should use use the string captured from the window title to search for the song's lyrics and display them to the user.

I'm currently using KDE4 as my desktop environment and I just need to be 'pointed in the right direction' on how I can capture the string that belongs to the window title for last.fm client.

Thanks!

Was it helpful?

Solution

You can use the wmctrl utility through the subprocess module. You can type wmctrl -l into a terminal and see the output you can get from it.

OTHER TIPS

I think by using a automation framework you may be able to achieve this as a subset. e.g. try dogtail(https://fedorahosted.org/dogtail/), it can focus on windows by name, click on buttons by name, so in the src code you may be able to see how to get title.

Have a look at X11 utilities, specifically xlsclients and xprop.

As an example, this is the shell commands I used to get info about my firefox window:

id_=$(xlsclients -al|grep "Command:  firefox-bin" -A1 -B4|head -n1|cut -d ' ' -f 2|tr -d ':')
xprop -id "$_id"

Output:

SM_CLIENT_ID(STRING) = "1181f048b9000125508490000000037360008"
WM_CLASS(STRING) = "firefox-bin", "Firefox-bin"
WM_COMMAND(STRING) = { "firefox-bin" }
WM_CLIENT_LEADER(WINDOW): window id # 0x0
_NET_WM_PID(CARDINAL) = 4265
WM_LOCALE_NAME(STRING) = "no_NO"
WM_CLIENT_MACHINE(STRING) = "gnom.ifi.uio.no"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
                program specified size: 10 by 10
WM_PROTOCOLS(ATOM): protocols  WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING
WM_ICON_NAME(STRING) = "firefox-bin"
_NET_WM_ICON_NAME(UTF8_STRING) = 0x66, 0x69, 0x72, 0x65, 0x66, 0x6f, 0x78, 0x2d, 0x62, 0x69, 0x6e
WM_NAME(STRING) = "Firefox"
_NET_WM_NAME(UTF8_STRING) = 0x46, 0x69, 0x72, 0x65, 0x66, 0x6f, 0x78

Try using dcop and piloting kwin. You can probably list all the window titles.

See the following for an example on how to use dcop: http://docs.kde.org/stable/en/kdegraphics/ksnapshot/dcop.html

another answer maybe to check if the application publishes the song change to DBus. if it does then you can just listen for the event and act on that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top