Determine whether Gnome desktop is visible in bash
I have a little bash script to display a webcam feed on my desktop. To conserve bandwidth, I only want the script to fetch new images when the Gnome desktop is actually visible. I.e., I don't want to do it when the power applet has turned off the screen, when the screensaver is active/locked, or when other windows are obscuring the desktop.
I've played around with commands like "gnome-screensaver-command -q" and "wmctrl -lG", but it quickly gets messy because the script has to parse the string output of these commands to figure out what's going on.
Does anyone know if there is a neater way of answering the question? Also, I haven't been able to find any way of determining whether the power applet has turned off the screen, so suggestions there would be very welcome.