Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@domwrap
Created July 18, 2018 00:29
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 domwrap/49bcd17083a79eafcde69afd3fb8c70e to your computer and use it in GitHub Desktop.
Save domwrap/49bcd17083a79eafcde69afd3fb8c70e to your computer and use it in GitHub Desktop.
Quick script to put program windows back on a specified screen. Made to make life easier when constantly (un)docking my laptop from two monitors
; REQUIRES AutoHotKey
; https://autohotkey.com/
#NoEnv
#Persistent
#SingleInstance Force
SetTitleMatchMode, 2
; ================================
; CHANGE THIS TO YOUR OWN PREFERENCES
; Key:Value list of program name (from Window Spy) to screen number,
; determines which programs go on which monitor, where 1 = left-most
; Currently limited to 3 screens, but very easily expanded
arrWindows := { OUTLOOK: 3, chrome: 2 }
; ================================
; LEAVE THE REST
; ================================
; BELOW BE DRAGONS
; ================================
; Retrieve size and coords of each screen
; Weirdly monitor 1 == 0, so we skip it
SysGet, Mon0, Monitor, 0
SysGet, Mon2, Monitor, 2
SysGet, Mon3, Monitor, 3
arrPos := [ Mon0Left, Mon2Left, Mon3Left ]
; Drink the potion, GUMMY BEEEEARS!
; Window window boing boing
for strExe, intMon in arrWindows
{
; Find all windows of each defined exe
WinGet, arrFound, list, ahk_exe %strExe%.exe
; Iterate over found windows and move them to specified screen
i := 1
Loop
{
; Have to compile this outside each command due to AHK's weird interpreter
idWin = % arrFound%i%
; Such move. Much maximize. Wow.
WinActivate, ahk_id %idWin%
WinRestore, ahk_id %idWin%
WinSet, Style, 0x40000
WinSet, Redraw
WinMove, ahk_id %idWin%, , arrPos[intMon], 0
WinMaximize, ahk_id %idWin%
i++
}
Until i = arrFound+1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment