├── .gitignore ├── DockWin.ahk ├── DockWin.exe ├── DockWin.ico ├── README.md └── _config.yml /.gitignore: -------------------------------------------------------------------------------- 1 | /WinPos.txt 2 | -------------------------------------------------------------------------------- /DockWin.ahk: -------------------------------------------------------------------------------- 1 | ;DockWin v0.7 - Save and Restore window positions when docking/undocking (using hotkeys) 2 | ; Paul Troiano, 6/2014 3 | ; Updated by Ashley Dawson 7/2015 4 | ; Updated by Carlo Costanzo 11/2016 5 | ; Updated by Rene Weselowski 7/2017,9/2017 6 | ; 7 | ; To use comandline switches compile as exe and use: 8 | ; /restore - restore Window-Configuration on start 9 | ; 10 | ; Hotkeys: ^ = Control; ! = Alt; + = Shift; # = Windows key; * = Wildcard; 11 | ; & = Combo keys; Others include ~, $, UP (see "Hotkeys" in Help) 12 | 13 | ;#InstallKeybdHook 14 | #SingleInstance, Force 15 | SetTitleMatchMode, 2 ; 2: A window's title can contain WinTitle anywhere inside it to be a match. 16 | SetTitleMatchMode, Fast ;Fast is default 17 | DetectHiddenWindows, off ;Off is default 18 | SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 19 | CrLf=`r`n 20 | FileName:="WinPos.txt" 21 | 22 | FileInstall, DockWin.ico, %A_ScriptDir%\DockWin.ico 23 | Menu, Tray, Icon, %A_ScriptDir%\DockWin.ico,, 1 24 | 25 | WinTitle = DockWin v0.7 26 | Menu, Tray, Icon 27 | Menu, Tray, Tip, %WinTitle%:`nCapture and Restore Screens ; `n is a line break. 28 | Menu, Tray, NoStandard 29 | 30 | Menu, Tray, Add, %WinTitle%, mDoNothing 31 | Menu, Tray, Default, %WinTitle% 32 | Menu, Tray, Disable, %WinTitle% 33 | Menu, Tray, Add ; time for a nice separator 34 | Menu, Tray, Add, Edit WinPos.txt, mEdit 35 | Menu, Tray, Add, Capture Screens - Shift+Win+0, mCapture 36 | Menu, Tray, Add, Restore Screens - Win+0, mRestore 37 | Menu, Tray, Add ; time for a nice separator 38 | Menu, Tray, Add, Exit %WinTitle%, mExit 39 | 40 | Loop, %0% { ;for each command line parameter 41 | If (%A_Index% = "/restore") ;check if known command line parameter exists 42 | Goto, mRestore 43 | } 44 | 45 | Return 46 | 47 | ; ======= 48 | mEdit: 49 | ; ======= 50 | 51 | Run, Notepad %A_WorkingDir%\%FileName%, %A_WorkingDir%, UseErrorLevel 52 | 53 | Return ; failsafe / probably never hits this line 54 | 55 | ; ==== 56 | mExit: 57 | ; ==== 58 | 59 | ExitApp, 0 60 | 61 | 62 | ;Win-0 (Restore window positions from file) 63 | 64 | #0:: 65 | mRestore: 66 | WinGetActiveTitle, SavedActiveWindow 67 | ParmVals:="Title x y height width maximized path" 68 | SectionToFind:= SectionHeader() 69 | SectionFound:= 0 70 | 71 | Loop, Read, %FileName% 72 | { 73 | if !SectionFound 74 | { 75 | ;Read through file until correct section found 76 | If (A_LoopReadLine<>SectionToFind) 77 | Continue 78 | } 79 | 80 | ;Exit if another section reached 81 | If ( SectionFound and SubStr(A_LoopReadLine,1,8)="SECTION:") 82 | Break 83 | 84 | SectionFound:=1 85 | 86 | Win_Title:="", Win_x:=0, Win_y:=0, Win_width:=0, Win_height:=0, Win_maximized:=0 87 | 88 | Loop, Parse, A_LoopReadLine, CSV 89 | { 90 | EqualPos:=InStr(A_LoopField,"=") 91 | Var:=SubStr(A_LoopField,1,EqualPos-1) 92 | Val:=SubStr(A_LoopField,EqualPos+1) 93 | IfInString, ParmVals, %Var% 94 | { 95 | ;Remove any surrounding double quotes (") 96 | If (SubStr(Val,1,1)=Chr(34)) 97 | { 98 | StringMid, Val, Val, 2, StrLen(Val)-2 99 | } 100 | Win_%Var%:=Val 101 | } 102 | } 103 | 104 | ;Check if program is already running, if not, start it 105 | If (!WinExist(Win_Title) and (Win_path<>"")) 106 | { 107 | Try 108 | { 109 | Run %Win_path% 110 | sleep 1000 ;Give some time for the program to launch. 111 | } 112 | } 113 | 114 | If ( (Win_maximized = 1) and WinExist(Win_Title) ) 115 | { 116 | WinRestore 117 | WinActivate 118 | WinMove, A,,%Win_x%,%Win_y%,%Win_width%,%Win_height% 119 | WinMaximize, A 120 | } Else If ((Win_maximized = -1) and (StrLen(Win_Title) > 0) and WinExist(Win_Title) ) ; Value of -1 means Window is minimised 121 | { 122 | WinRestore 123 | WinActivate 124 | WinMove, A,,%Win_x%,%Win_y%,%Win_width%,%Win_height% 125 | WinMinimize, A 126 | } Else If ( (StrLen(Win_Title) > 0) and WinExist(Win_Title) ) 127 | { 128 | WinRestore 129 | WinActivate 130 | WinMove, A,,%Win_x%,%Win_y%,%Win_width%,%Win_height% 131 | } 132 | } 133 | 134 | if !SectionFound 135 | { 136 | msgbox,,Dock Windows, Section does not exist in %FileName% `nLooking for: %SectionToFind%`n`nTo save a new section, use Win-Shift-0 (zero key above letter P on keyboard) 137 | } 138 | 139 | ;Restore window that was active at beginning of script 140 | WinActivate, %SavedActiveWindow% 141 | RETURN 142 | 143 | 144 | ;Win-Shift-0 (Save current windows to file) 145 | #+0:: 146 | mCapture: 147 | 148 | MsgBox, 4,Dock Windows,Save window positions? (it will append to the file!) 149 | IfMsgBox, NO, Return 150 | 151 | WinGetActiveTitle, SavedActiveWindow 152 | 153 | file := FileOpen(FileName, "a") 154 | if !IsObject(file) 155 | { 156 | MsgBox, Can't open "%FileName%" for writing. 157 | Return 158 | } 159 | 160 | line:= SectionHeader() . CrLf 161 | file.Write(line) 162 | 163 | ; Loop through all windows on the entire system 164 | WinGet, id, list,,, Program Manager 165 | Loop, %id% 166 | { 167 | this_id := id%A_Index% 168 | WinGetClass, this_class, ahk_id %this_id% 169 | WinGetTitle, this_title, ahk_id %this_id% 170 | WinGet, win_maximized, minmax, ahk_class %this_class% 171 | WinActivate, ahk_id %this_id% 172 | WinGetPos, x, y, Width, Height, A ;Wintitle 173 | 174 | if ( (StrLen(this_title)>0) and (this_title<>"Start") ) 175 | { 176 | line=Title="%this_title%"`,x=%x%`,y=%y%`,width=%width%`,height=%height%`,maximized=%win_maximized%,path=""`r`n 177 | file.Write(line) 178 | } 179 | 180 | if(win_maximized = -1) ;Re-minimize any windows that were minimised before we started. 181 | { 182 | WinMinimize, A 183 | } 184 | } 185 | 186 | file.write(CrLf) ;Add blank line after section 187 | file.Close() 188 | 189 | ;Restore active window 190 | WinActivate, %SavedActiveWindow% 191 | RETURN 192 | 193 | ; ------- 194 | 195 | ;Create standardized section header for later retrieval 196 | SectionHeader() 197 | { 198 | SysGet, MonitorCount, MonitorCount 199 | SysGet, MonitorPrimary, MonitorPrimary 200 | line=SECTION: Monitors=%MonitorCount%,MonitorPrimary=%MonitorPrimary% 201 | 202 | WinGetPos, x, y, Width, Height, Program Manager 203 | line:= line . "; Desktop size:" . x . "," . y . "," . width . "," . height 204 | 205 | Return %line% 206 | } 207 | 208 | ; ===== 209 | mDoNothing: ; for labels. 210 | ; ===== 211 | -------------------------------------------------------------------------------- /DockWin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwese/DockWin/8a0d23b0bf7810b4dae684b783c9f686cbb8dff8/DockWin.exe -------------------------------------------------------------------------------- /DockWin.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwese/DockWin/8a0d23b0bf7810b4dae684b783c9f686cbb8dff8/DockWin.ico -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Abandoned 2 | 3 | I've since switched to primarely use linux, thus I can't maintain this script anymore. 4 | 5 | Please feel free to fork this repository and continue on. 6 | 7 | # DockWin 8 | Autohotkey(https://autohotkey.com/) Script to save and restore positions of windows. 9 | 10 | Used to replace windows after switching monitor arrangement, un/docking a notebook etc. 11 | 12 | ## Hotkeys 13 | 14 | - **[Win]+0** = Restore window positions from ./WinPos.txt 15 | - **[Win]+[Shift]+0** = Save window positions to ./WinPos.txt 16 | 17 | ## Menu 18 | DockWin sits quietly in the tool tray and can be right clicked to edit WinPos.txt or initiate a capture or restore. 19 | 20 | ### WinPos.txt 21 | 22 | ``` 23 | SECTION: Monitors=2,MonitorPrimary=1; Desktop size:0,0,4480,1440 24 | Title="Sublime Text",x=-8,y=-8,width=2576,height=1416,maximized=1,path="" 25 | Title="sshsession@server:Default",x=3520,y=18,width=960,height=1062,maximized=0,path="" 26 | ``` 27 | 28 | ## Saved 29 | 30 | ## Original Source 31 | https://autohotkey.com/board/topic/112113-dockwin-storerecall-window-positions/page-3 32 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal --------------------------------------------------------------------------------