Skip to content

Instantly share code, notes, and snippets.

@AimForNaN
Created November 29, 2017 21:07
Show Gist options
  • Save AimForNaN/c3b11530494f3454ce52d66c07c7537e to your computer and use it in GitHub Desktop.
Save AimForNaN/c3b11530494f3454ce52d66c07c7537e to your computer and use it in GitHub Desktop.
Will position a window onto the main screen to x(0) y(0) with size width(800) height(800)
"""
Usage: python bring-back-window.py [--title WindowTitle]
Example: python bring-back-window.py --title "Create a new Gist - Google Chrome"
Depends on Python 3 and pywin32.
"""
import argparse, win32gui;
def enum(hwnd, extra):
name = win32gui.GetWindowText(hwnd);
# Minor black list!
if name and name not in ('Default IME', 'MSCTFIME UI'):
try:
print(name);
pass;
except Exception as e:
pass;
if name == enum.window:
win32gui.MoveWindow(hwnd, 0, 0, 800, 800, True);
enum.window = None;
def main():
parser = argparse.ArgumentParser(description='Bring back my window!');
parser.add_argument('--title', type=str, help='Title of window', dest='window', required=False);
args = parser.parse_args();
enum.window = args.window;
win32gui.EnumWindows(enum, None);
if __name__ == '__main__':
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment