Page 1 of 1

API to get native window ID?

Unread postPosted: Wed Oct 02, 2019 12:43 pm
by briansilva
Hello! I'm setting up some automated screen grabbing, and it would be very useful to get the native window ID for the Clarisse window. Is there any way to get this from the Clarisse API? A process number might also be enough to roll a solution.


Re: API to get native window ID?

Unread postPosted: Wed Oct 02, 2019 1:39 pm
by anemoff
To get Clarisse process ID, assuming the script is running in Clarisse, it's as simple as this

python code

import os

There's no Clarisse API to get the Clarisse window ID.
But you should be able to get it from the PID using platform-specific code or tools.

Here is an example, for Linux, based on the 3rdparty tool "wmctrl":

python code

import os
import subprocess

def get_clarisse_winid():
Gets the window ID (as an integer) of the current Clarisse instance.

# get Clarisse PID to find the corresponding window ID
clarisse_pid = os.getpid()
#print('[debug] Clarisse PID: {}'.format(clarisse_pid))

winid = None
# list all window IDs with their PID
# you need to instal "wmctrl" on your system
output = subprocess.check_output("wmctrl -l -p", shell = True)

# keep only the lines for Clarisse app
# there might be multiple matches if there are multiple Clarisse instances running
clarisse_title = 'Isotropix Clarisse'
matches = [line for line in output.splitlines() if clarisse_title in line]

# find the window that matches Clarisse PID
for line in matches:
# each output line is formatted as follows:
# "window_id desktop_number pid window_name"
parts = line.split()
if len(parts) >= 3 and int(parts[2]) == clarisse_pid:
# the window ID is in hexadecimal, convert to decimal
winid = int(parts[0], 0)
#print('[debug] Clarisse window ID: hex = {}, dec = {}'.format(parts[0], winid))

except subprocess.CalledProcessError as e:
except Exception as e:

return winid


Re: API to get native window ID?

Unread postPosted: Wed Nov 20, 2019 12:10 pm
by briansilva
That's great Anthony, thanks for the example!