From ohcanada, 2 Weeks ago, written in Bash.
  1. #!/bin/bash
  2.  
  3. ACTIVE_WIN=$(xprop -root _NET_ACTIVE_WINDOW)
  4.  
  5. ID_RE='[^ ]+$'
  6. WIN_ID=$([[ $ACTIVE_WIN =~ $ID_RE ]] && echo ${BASH_REMATCH})
  7.  
  8. WIN_CLASS=$(xprop -id $WIN_ID WM_CLASS)
  9.  
  10. CLASS_RE='(")([^ ]+)("$)'
  11. CLASS=$([[ $WIN_CLASS =~ $CLASS_RE ]] && echo ${BASH_REMATCH[2]})
  12.  
  13. # Fallback is window name from xdotool (shows i3 for root window)
  14. [[ -z $CLASS ]] && CLASS=$(xdotool getwindowfocus getwindowname)
  15. [[ -z $CLASS ]] && CLASS=Unknown
  16.  
  17. echo $CLASS
  18. echo
  19. echo \#C0C000
captcha