Is it possible to retrieve the active window process/title in Gnome?
It is as simple as this:
xdotool getactivewindow getwindowname
Good luck hope it works for you!
You can use xdotool, a versatile X window automation tool.
focused_window_id=$(xdotool getwindowfocus)
active_window_id=$(xdotool getactivewindow)
active_window_pid=$(xdotool getwindowpid "$active_window_id")
(I don't know what the difference between focused and active is.)
(I thought wmctrl could do this, but apparently not.)
Simpler (IMO) than OP's solution (i.e. without ps
, grep
and awk
), to get the process name :
cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm
Or if you want an end of line :
echo $(cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm)