Given a process iD of XX, I'd like to have a list of any window id's where _NET_WM_PID = XX. Even better would be the oldest still active window id if possible.
I'm very new to linux, but what I'm trying to do is create a script that would take a command line, and see if there's a windows already open belonging to a process invoked with that same command line. If so, just set focus to that window, otherwise execute the command line to get a new process going. My intention is to use this in my ubuntu desktop, where I'll hook this script into my easystroke mouse gesture commands, so that, for example, every time I gesture for gmail I don't get a brand new gmail session, I just get brought to my existing gmail chrome app window. Perhaps there's a much easier way to go about all this, but I haven't found my way to it yet.
With help, I've figured out how find a PID for a command line with pgrep and how to set focus to a window handle with wmctrl, but I'm stuck on getting from PID to window ID.