Automatically Restore Last Window Position For Each Process

Post your working scripts, libraries and tools
gallaxhar
Posts: 143
Joined: 03 Sep 2014, 06:35

Automatically Restore Last Window Position For Each Process

16 May 2016, 20:54

This is a truly automatic window manager (saves window positions, even snapped ones) with no user input or setup, you don't have to specify what windows should be what size and go where like other with other window managers, it just works, based on the previous window position. Windows OS can't save snapped-window locations. This really bothered me as all day long I was having to re-snap windows.

Image

This script works by getting the current active window information (id and processname). It saves the latest window size/pos to an ini file, and reads from that ini file when new window ID's become active. It's smart enough to not auto-size existing windows from before the script is run, it will only autosize new ID's, and it will only do so one time for that ID.

The one thing you may need to set up is this script to start with windows automatically, if you want to use it for more than just a test run. I have RegistryAdd and RegistryRemove files separate from the script so you can run the script without adding it to the registry, if you like it and want it to start in the background automatically (so it's actually useful to you), download RegistryAdd in the same directory, and run the main script again, it will silently add it to the registry, then delete the RegistryAdd.ahk file, likewise you can download RegistryRemove in the same directory, and run the main script to remove the startup registry entry. Remember to remove RegistryAdd or RegistryRemove after you use either of them, so they continually run (no harm in that other than it may prompt you for UAC elevation to run as admin every time you boot up).

Code: [Select all] [Expand] [Download] (AutomaticWindowManager.ahk)GeSHi © Codebox Plus



Code: [Select all] [Download] (RegistryAdd.ahk)GeSHi © Codebox Plus

if not A_IsAdmin
{
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run, "%A_ScriptName%", "C:\Program Files\AutoHotkey\AutoHotkey.exe" "%A_ScriptFullPath%"


Code: [Select all] [Download] (RegistryDelete.ahk)GeSHi © Codebox Plus

if not A_IsAdmin
{
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
RegDelete, HKEY_LOCAL_MACHINE, SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run, "%A_ScriptName%"
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

02 Feb 2017, 08:16

Simple,elegant,automated and exactly what I was looking. Thanks a f$#!k ton dude,tons better than alternatives that require manual interaction...
Outsourcing Clicks & Presses Since 2004.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

05 Feb 2017, 13:55

I find that it's a bit vulgar in how it tries to resize dialog boxes to their parents windows and so forth so here's a tweaked version that instead of using an exclusion list uses a filter to decide which programs get resized,only name of exe need be defined just as in the prior exclusion list.

Code: [Select all] [Expand] [Download] (AutomaticWindowManager.ahk)GeSHi © Codebox Plus

Outsourcing Clicks & Presses Since 2004.
nathan323
Posts: 36
Joined: 31 Jan 2016, 02:53

Re: Automatically Restore Last Window Position For Each Process

07 Feb 2017, 04:39

Great work gallaxhar :)

brutus, I agree that dialog boxes being snapped are definitely not ideal. But as I have seen when using your version - if I add a program to the filter to be snapped, that program will have its dialog boxes snapped too, so doesn't fix?
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

07 Feb 2017, 12:48

nathan323, yeah I'm lookin to fix that if you don't beat me to it,it's just a matter of filtering the dialog box Window class from it's parent exe's class,my tweak just limits the oddity of morphed dialog boxes ONLY to programs you have specified instead of every dialog box you ever open, I think for now at least that's a worthwhile tweak don't you...
Outsourcing Clicks & Presses Since 2004.
nathan323
Posts: 36
Joined: 31 Jan 2016, 02:53

Re: Automatically Restore Last Window Position For Each Process

07 Feb 2017, 13:56

Yeah for sure. I had a prog for a while called Display Fusion, did a lot of windows management. Ended up turfing it because too buggy, but they had an option to limit snapping only to windows of a certain starting size (ie. pixels), that might be something we can to play with..
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

08 Feb 2017, 07:25

Here's a full functioning tweak,it only resizes and moves the specified exe and doesn't alter dialog boxes opened from the process,it basically takes the class name of the specified program the first time it detects it,after that the class name for exe's main window won't change and it uses the difference in classname between dialog boxes of a window and the main window it self,i've also filtered the standard windows Open/Save dialog box class #32770.

Code: [Select all] [Expand] [Download] (AutomaticWindowManager.ahk)GeSHi © Codebox Plus

Outsourcing Clicks & Presses Since 2004.
pk23
Posts: 47
Joined: 24 Apr 2015, 00:49

Re: Automatically Restore Last Window Position For Each Process

29 Aug 2017, 12:23

@brutus_skywalker
Sometimes, even with the same exe and class, they are completely different window. Like the program written by Qt. This script has a very bad effect if used on anki desktop.

It maybe better if the script match the “exe+class+title” triad of the window.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

29 Aug 2017, 14:29

pk23 wrote:@brutus_skywalker
Sometimes, even with the same exe and class, they are completely different window. Like the program written by Qt. This script has a very bad effect if used on anki desktop.

It maybe better if the script match the “exe+class+title” triad of the window.



That would be a hell of a mess though,take a browser for instance where the title of a window changes every page. Though you could easily add title checking specifically for anki provided it have a static title,though instead of a title you might prefer using strings in the main window that only exists in the main window context such as 'file,open,help,...' and other such text that are only present in the main window.
Outsourcing Clicks & Presses Since 2004.
mankvl
Posts: 11
Joined: 23 Sep 2016, 03:58

Re: Automatically Restore Last Window Position For Each Process

02 Mar 2018, 10:17

Would be nice to have title ExclusionList. I wan't main outlook windows to be maximized but new message only half screen. Is this possible ?
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

09 Mar 2018, 09:53

mankvl wrote:Would be nice to have title ExclusionList. I wan't main outlook windows to be maximized but new message only half screen. Is this possible ?


This should allow you to filter out altering the position of a filtered application so long as it's title is also blacklisted against resizing or moving... just add the title you wish to filter in a new line as shown below, there should be a Title_Filter variable to which you can add titles to filter just under the application filter list. ;)

Code: [Select all] [Download] GeSHi © Codebox Plus

Title_Filter =		;add every new title on a new line
(
Automatically Restore Last Window Position For Each Process - AutoHotkey Community - Mozilla Firefox
)


Code: [Select all] [Expand] [Download] (AutomaticWindowManager.ahk)GeSHi © Codebox Plus

Outsourcing Clicks & Presses Since 2004.
timblaktu
Posts: 1
Joined: 15 Mar 2018, 15:51
Facebook: Tim Black
Google: Tim Black
GitHub: timblaktu

Re: Automatically Restore Last Window Position For Each Process

15 Mar 2018, 16:12

I was trying to "uninstall" this ahk script, and have followed @gallaxhar's instructions (run main script with RegistryDelete.ahk colocated) multiple times and every time I reboot it (something) was still trying to run the AutomaticWindowManager.ahk script. I simply moved the script, and then found of course it doesn't run at boot but I do get a dialog saying it cannot find the script.

I searched my entire registry for the string "AutomaticWindowManager" in keys, values, and data, and got zero hits. Then I searched without "match whole string" and found an entry in:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run

that was trying to run AutomaticWindowManager.ahk.

I deleted that, and now my system doesn't try to run it every boot.

Any ideas why RegistryDelete.ahk didn't work?

Anyway, nice script, but I was annoyed at the effect it had on dialogs, so I am using this now:
https://github.com/rwese/DockWin
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

16 Mar 2018, 22:47

timblaktu wrote:I was trying to "uninstall" this ahk script, and have followed @gallaxhar's instructions (run main script with RegistryDelete.ahk colocated) multiple times and every time I reboot it (something) was still trying to run the AutomaticWindowManager.ahk script. I simply moved the script, and then found of course it doesn't run at boot but I do get a dialog saying it cannot find the script.

I searched my entire registry for the string "AutomaticWindowManager" in keys, values, and data, and got zero hits. Then I searched without "match whole string" and found an entry in:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run

that was trying to run AutomaticWindowManager.ahk.

I deleted that, and now my system doesn't try to run it every boot.

Any ideas why RegistryDelete.ahk didn't work?

Anyway, nice script, but I was annoyed at the effect it had on dialogs, so I am using this now:
https://github.com/rwese/DockWin



It needs to be run as admin, tested it & it works just fine, and thanks for linking an alternative, though DockWin is a MANUAL alternative hence why it has no 'dialog box' issues.
Outsourcing Clicks & Presses Since 2004.
robhayes
Posts: 19
Joined: 28 Dec 2015, 15:35

Re: Automatically Restore Last Window Position For Each Process

20 Mar 2018, 13:20

How do I uninstall this script? I don't like it's behaviour with popup menus and folders.

I've tried just deleting the files, but it appears to be called in my startup somewhere, and I can't find it.
User avatar
gregster
Posts: 1185
Joined: 30 Sep 2013, 06:48

Re: Automatically Restore Last Window Position For Each Process

20 Mar 2018, 13:55

Well, it seems you have to place the RegDelete file with the right name (see last code box: RegistryDelete.ahk) in the same directory and run the main file again - description is in the first post.
robhayes
Posts: 19
Joined: 28 Dec 2015, 15:35

Re: Automatically Restore Last Window Position For Each Process

21 Mar 2018, 12:54

gregster wrote:Well, it seems you have to place the RegDelete file with the right name (see last code box: RegistryDelete.ahk) in the same directory and run the main file again - description is in the first post.


This did not work for me. Is there a certain reg file I can manually delete? This script completely broke my multi-screen Photoshop and Illustrator setups, making the programs unusable and messing with the DPI.

Thanks in advance for your assistance.
User avatar
gregster
Posts: 1185
Joined: 30 Sep 2013, 06:48

Re: Automatically Restore Last Window Position For Each Process

21 Mar 2018, 14:16

It should be the key from the RegistryDelete.ahk - you can see in RegistryAdd.ahk that is was added there...

Code: [Select all] [Download] GeSHi © Codebox Plus

HKEY_LOCAL_MACHINE, SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run, "%A_ScriptName%"
Obviously, the actual script name depends on how you named the main script, but the key should be this one.

Or, did you manually add a shortcut to your window's startup folder?

I've tried just deleting the files, but it appears to be called in my startup somewhere, and I can't find it.
How do you know? What is the error message? Did you reboot since then or is the script still running in memory?
robhayes
Posts: 19
Joined: 28 Dec 2015, 15:35

Re: Automatically Restore Last Window Position For Each Process

21 Mar 2018, 15:12

Thank you for pointing out where I could find the registry key that needed to be deleted. Problem solved.
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

25 Mar 2018, 14:09

gallaxhar, Thx for your script.

There is issue with Taskmgr.exe. The window doesn't appear at the right place.

Windows OS can't save snapped-window locations.

I think It's not exactly true. All of non windows application i have tried work pretty well with the save of the snapped-window location. There is an issue with Firefox which doesn't appear exactly at the same place.
The big issue is with some microsoft applications like onenote, Skype, task manager, note, etc.
Last edited by ovnis on 25 Mar 2018, 22:29, edited 2 times in total.
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

25 Mar 2018, 21:48

Hello Brutus,

Thx for your script, but there are problems.

There are issues with Taskmgr.exe and explorer.exe. Windows don't appear at the right place.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 6 guests