Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Created July 24, 2021 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbnorth/95677ab810a86e0e5d60de393297b484 to your computer and use it in GitHub Desktop.
Save tbnorth/95677ab810a86e0e5d60de393297b484 to your computer and use it in GitHub Desktop.
Relocate Windows 10 windows with Python script
"""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