Skip to content

PyGetWindow not Supported on Linux #1

@elhamoudrayan

Description

@elhamoudrayan

PyGetWindow does not Support Linux
The Error occured in visual_parser.py while importing the package
Try using xdotool and wmctrl for Linux because there is no cross platform Library

Maybe try this change all over the code :

import sys

def get_active_window_title():
    if sys.platform.startswith('win'):
        import pygetwindow as gw
        win = gw.getActiveWindow()
        return win.title if win else None
    elif sys.platform == 'darwin':
        import pygetwindow as gw
        win = gw.getActiveWindow()
        return win.title if win else None
    elif sys.platform.startswith('linux'):
        import subprocess
        try:
            output = subprocess.check_output(['xdotool', 'getactivewindow', 'getwindowname'])
            return output.decode().strip()
        except Exception:
            return None
    else:
        return None

print("Active window:", get_active_window_title())
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions