One of the minor little issues I’ve had since this whole “work from home” thing started is that I frequently need to switch back and forth between using my laptop on its own vs. remoting into it from my desktop PC. I always need to be connected to our work VPN, and we’re not allowed to install the VPN client on personal PCs. And I don’t have an easy way to connect my personal monitor, mouse, and keyboard to the laptop. (Yes, I know there are a bunch of reasonably easy ways to do that. I just haven’t made the effort.) So I spend most of the day remoted in to the laptop via RDP from my desktop PC. But I disconnect and use the laptop directly whenever I need to be in a meeting, so I can use the camera and microphone. (And, yes, there’s probably a way for me to use the camera and mic while remoted in, but I haven’t bothered to try figuring that out either.)
Anyway, the issue with all that is that the change in resolution between the laptop screen and my desktop monitor confuses things, so my window sizes and positions are generally all screwed up when I do that. So I wanted to write a little AutoHotKey script to automatically move and resize the windows for my most commonly-used programs. (In my case: Outlook, OneNote, and Firefox. I do my actual development work via RDP into a VM, not on my “real” computer, so it’s just the productivity stuff running on the laptop.)
Of course, given the way these things tend to go, I just lived with it until June, when I finally got around to writing the script. And, again, of course, I found issues with the script, but didn’t bother correcting them until… today. So here’s a script that looks at the current monitor’s resolution, then moves and resizes Outlook, OneNote, and Firefox so they’re tiled and just the right size for my preferences.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
SysGet, Mon1, Monitor ;MsgBox, screen dimensions: %Mon1Right% x %Mon1Bottom% X := 70 Y := 32 Width := Mon1Right - 240 Height := Mon1Bottom - 150 ;MsgBox, X=%X%, Y=%Y%, Width=%Width%, Height=%Height% WinRestore, ahk_exe OUTLOOK.EXE WinMove, ahk_exe OUTLOOK.EXE,, X, Y, Width, Height WinRestore, ahk_exe firefox.exe WinMove, ahk_exe firefox.exe,, X*2, Y*2, Width, Height WinRestore, ahk_exe ONENOTE.EXE WinMove, ahk_exe ONENOTE.EXE,, X*3, Y*3, Width, Height
I also considered using PowerShell with WASP for this, but I’m more familiar with AHK.