#!/usr/bin/perl # # Outputs the ID of the active window # in C hex format, e.g. 0x602f9a. # If no window is active, it outputs 0x0. # use strict; use warnings; { $_ = `xprop -root _NET_ACTIVE_WINDOW`; # e.g. _NET_ACTIVE_WINDOW(WINDOW): window id # 0x602f9a /id \# (0x[0-9a-f]+)$/ or die; my $active_window_ID = $1; # e.g. 0x602f9a print "$active_window_ID\n"; }