gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
how to get list of all apps that are opened (i dont care about processes) i only want…
- 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
- Assistant
You can achieve this by using the
psutillibrary 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): passThis code uses the
wmctrlcommand-line tool to get the list of open windows for each process. You'll need to make surewmctrlis installed on your system before running this code.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.