Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

how to get list of all apps that are opened (i dont care about processes) i only want…

  1. User

    how to get list of all apps that are opened (i dont care about processes) i only want the apps i have opened. right now that is pycharm and google chrome but obviously thats gonna change. how can i do that in python code

  2. Assistant

    You can achieve this by using the psutil library in python. Here's an example code that lists all running processes and their corresponding open windows:

    import psutil
    import subprocess
    
    # get all running processes
    for proc in psutil.process_iter():
        try:
            # get process information
            pinfo = proc.as_dict(attrs=['pid', 'name'])
            # get process name
            pname = pinfo['name']
            # get list of open windows for process
            windows = subprocess.check_output(['wmctrl', '-lp']).decode('utf-8').strip().split('\n')
            for window in windows:
                winfo = window.split()
                if winfo[3] == str(pinfo['pid']):
                    # print process name and window title
                    print(pname, winfo[4:])
                    break
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
            pass
    

    This code uses the wmctrl command-line tool to get the list of open windows for each process. You'll need to make sure wmctrl is installed on your system before running this code.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.