Tiling notepad.exe

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Newman1
Posts: 1
Joined: 03 Sep 2017, 05:46

Tiling notepad.exe

03 Sep 2017, 05:52

Hi all,

I am completely new ao AHK and would very much appreciate some help.

Often I have 30 notepad.exe or chrome open on my computer.

I would like a script which would find all the notepad.exe or perhaps a maximum number of them and tile them over all available monitors.

The reason for this is that I would then close the ones I dont want and not save them but you can see which ones you can close straight away.

I would also like to do it with chrome.

Can anyone offer a script for this please?

Your help is much appreciated, I tried searching the forums but couldnt find something.

Many thanks in advance.
Newman
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Tiling notepad.exe

03 Sep 2017, 12:57

Right click your task bar and choose "windows side by side", Viola.. :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Tiling notepad.exe

03 Sep 2017, 13:37

I only ever use one monitor, however it may be that this script can be adapted to multiple monitors.

If anyone has written similar scripts to this, please share a link. Cheers.

Code: Select all

q:: ;tile Notepad/Chrome windows
DetectHiddenWindows, Off
WinGet, vWinList, List
vList := "", vCount := 0
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	;WinGetClass, vWinClass, % "ahk_id " hWnd
	WinGet, vPName, ProcessName, % "ahk_id " hWnd
	;if (vPName = "notepad.exe")
	;if (vPName = "chrome.exe")
	if RegExMatch(vPName, "^(notepad.exe|chrome.exe)$")
		vList .= hWnd "`n", vCount += 1
}
vList := SubStr(vList, 1, -1)
Loop
{
	vNum := A_Index
	if (vCount <= vNum**2)
		break
}
WinGetPos,,,, vTaskbarH, ahk_class Shell_TrayWnd
vWinW := A_ScreenWidth / vNum
;vWinH := A_ScreenHeight / vNum
vWinH := (A_ScreenHeight-vTaskbarH) / vNum
vX := 0, vY := 0
oArray := StrSplit(vList, "`n")
Loop, Parse, vList, `n
{
	;hWnd := oArray[A_Index]
	hWnd := oArray[oArray.Length()+1-A_Index]
	vWinX := vX*vWinW
	vWinY := vY*vWinH
	WinMove, % "ahk_id " hWnd,, % vWinX, % vWinY, % vWinW, % vWinH
	vX++
	if (vX = vNum)
		vX := 0, vY += 1
}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Tiling notepad.exe

09 Sep 2017, 02:35

It was running a bit slower than I expected, and it turns out that the script pauses for 100 milliseconds after each WinMove based on SetWinDelay, so I've amended the script, setting the delay to 0 temporarily.

There are one or two other slight changes: activating each window, and actuating the original window at the end, but only if it was a Notepad/Chrome window.

Code: Select all

q:: ;tile Notepad/Chrome windows
DetectHiddenWindows, Off
WinGet, hWnd2, ID, A
hWnd3 := 0
WinGet, vWinList, List
vList := "", vCount := 0
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	if (hWnd = hWnd2)
		hWnd3 := hWnd2
	;WinGetClass, vWinClass, % "ahk_id " hWnd
	WinGet, vPName, ProcessName, % "ahk_id " hWnd
	;if (vPName = "notepad.exe")
	;if (vPName = "chrome.exe")
	if RegExMatch(vPName, "^(notepad.exe|chrome.exe)$")
		vList .= hWnd "`n", vCount += 1
}
vList := SubStr(vList, 1, -1)
Loop
{
	vNum := A_Index
	if (vCount <= vNum**2)
		break
}
WinGetPos,,,, vTaskbarH, ahk_class Shell_TrayWnd
vWinW := A_ScreenWidth / vNum
;vWinH := A_ScreenHeight / vNum
vWinH := (A_ScreenHeight-vTaskbarH) / vNum
vX := 0, vY := 0
oArray := StrSplit(vList, "`n")
vWD := A_WinDelay
SetWinDelay, 0
Loop, % oArray.Length()
{
	;hWnd := oArray[A_Index]
	hWnd := oArray[oArray.Length()+1-A_Index]
	vWinX := vX*vWinW
	vWinY := vY*vWinH
	;WinSet, Top,, % "ahk_id " hWnd
	;WinShow, % "ahk_id " hWnd
	WinActivate, % "ahk_id " hWnd
	;WinSet, AlwaysOnTop, Toggle, % "ahk_id " hWnd
	WinMove, % "ahk_id " hWnd,, % vWinX, % vWinY, % vWinW, % vWinH
	;WinSet, AlwaysOnTop, Toggle, % "ahk_id " hWnd
	vX++
	if (vX = vNum)
		vX := 0, vY += 1
}
SetWinDelay, % vWD
if hWnd3
	WinActivate, % "ahk_id " hWnd3
return
[1900th post]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Tiling notepad.exe

09 Sep 2017, 03:18

jeeswg wrote: [...] [1900th post]
:clap: :clap: :thumbup: :clap: :clap:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], peter_ahk and 162 guests