xprop -id $(xprop -root | grep '_NET_ACTIVE_WINDOW(WINDOW)' | cut -d' ' -f5)That gets you a bunch of useful information from which you can parse whatever you need, such as the window's title, class, or process ID. (WM_ICON_NAME, WM_CLASS and _NET_WM_PID, respectively.)
xprop -id `xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}'` | grep "WM_CLASS(STRING)"WM_CLASS(STRING) = "gnome-terminal", "Gnome-terminal"xprop -id `xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}'` | grep "WM_CLASS(STRING)" | sed -e 's/.*= "\([^"]*\)".*/\1/'
#!/bin/bash
xprop -id `xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}'` | grep "WM_CLASS(STRING)" | sed -e 's/.*= "\([^"]*\)".*/\1/'
topprog=`. topprog.sh`
xwit -current -print | cut -d ' ' -f7-xwit -current -print -property WM_COMMAND | cut -d"'" -f2
xwit -print|cut -d: -f1|xargs -I '}' xprop -id '}'|grep PID|cut -d' ' -f3|xargs -I '}' ps -p '}' -o comm=
`backtick command substitution` and always use $(parenthetical command substitution).xprop -root | awk '/^_NET_ACTIVE_WINDOW\(WINDOW\)/ {print $5}' | xargs xprop -id | awk '/^WM_CLASS\(STRING\)/ {gsub(/^"|",$/,"",$3); print $3}'I needed to start the patterns with ^ since otherwise the pattern sometimes showed up in the cut buffer. xwit looks nice but it looks like it's not universally available.
posted by fantabulous timewaster at 10:56 PM on May 12, 2010