Created
July 24, 2021 15:54
-
-
Save tbnorth/95677ab810a86e0e5d60de393297b484 to your computer and use it in GitHub Desktop.
Relocate Windows 10 windows with Python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Restore window layout in Windows 10 | |
One way of launching, git bash script .sh file: | |
eval "$('/c/Users/username/pkg/miniconda/Scripts/conda.exe' 'shell.bash' 'hook')" | |
python "C:/Users/username/scripts/movewin.py" | |
""" | |
import win32gui | |
import re | |
POSITIONS = [ | |
(r".*Google Chrome$", r"", 0, 0, 1680, 1000), | |
(r"", r"PuTTY", 1680, 0, 1920, 1010), | |
(r".*Microsoft Teams$", r"", 3605, 0, 1040, 1000), | |
(r"", r"", 0, 0, 760, 500), | |
(r"", r"", 0, 0, 760, 500), | |
(r"", r"", 0, 0, 760, 500), | |
(r"", r"", 0, 0, 760, 500), | |
(r"", r"", 0, 0, 760, 500), | |
] | |
def enumHandler(hwnd, lParam): | |
if win32gui.IsWindowVisible(hwnd): | |
title = win32gui.GetWindowText(hwnd) | |
class_ = win32gui.GetClassName(hwnd) | |
print(title) | |
print(" ", class_) | |
for title_re, class_re, x, y, w, h in POSITIONS: | |
if ( | |
title_re and re.match(title_re, title) or | |
class_re and re.match(class_re, class_) | |
): | |
win32gui.MoveWindow(hwnd, x, y, w, h, True) | |
win32gui.EnumWindows(enumHandler, None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment