Switch between open Windows of the same type and same App

Post your working scripts, libraries and tools for AHK v1.1 and older
JuanmaMenendez
Posts: 8
Joined: 11 Apr 2019, 18:25
Contact:

Switch between open Windows of the same type and same App

30 Apr 2019, 17:33

This AutoHotkey script is to switch between open Windows of the same type and same App (.exe)


The hotkey is (Alt + ~)

The "type" checking is based on the App's Title convention that stipulates that the App name should be at the end of the Window title (Eg: New Document - Word )

It works well with regular Window Apps, Chrome Shortcuts and Chrome Apps

Code: Select all

/* ;
*****************************
***** UTILITY FUNCTIONS *****
*****************************
*/


ExtractAppTitle(FullTitle)
{	
	AppTitle := SubStr(FullTitle, InStr(FullTitle, " ", false, -1) + 1)
	Return AppTitle
}



/* ;
***********************************
***** SHORTCUTS CONFIGURATION *****
***********************************
*/


; Alt + ` -  Activate NEXT Window of same type (title checking) of the current APP
!`::
WinGet, ActiveProcess, ProcessName, A
WinGet, OpenWindowsAmount, Count, ahk_exe %ActiveProcess%

If OpenWindowsAmount = 1  ; If only one Window exist, do nothing
    Return
	
Else
	{
		WinGetTitle, FullTitle, A
		AppTitle := ExtractAppTitle(FullTitle)

		SetTitleMatchMode, 2		
		WinGet, WindowsWithSameTitleList, List, %AppTitle%
		
		If WindowsWithSameTitleList > 1 ; If several Window of same type (title checking) exist
		{
			WinActivate, % "ahk_id " WindowsWithSameTitleList%WindowsWithSameTitleList%	; Activate next Window	
		}
	}
Return

Note: The Source Code with the last actualization can be found here https://github.com/JuanmaMenendez/AutoHotkey-script-Open-Show-Apps/blob/master/AutoHotkey-script-Switch-Windows-same-App.ahk


*** Extra ***

Also, I have another script that could work well in tandem with this one because you will be able to Open, Restore or Minimize (if it is already opened) the desired Apps, using the shortcuts key (hotkeys) that you want to set. Examples:

F7:: OpenOrShowAppBasedOnExeName("C:\Windows\System32\SnippingTool.exe")

F8:: OpenOrShowAppBasedOnWindowTitle("Gmail", "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --app=https mail.google.com /mail/") Broken Link for safety


Feel free to check my repo and give me your thoughts ;)

https://github.com/JuanmaMenendez/AutoHotkey-script-Open-Show-Apps


Thanks
zhotkey
Posts: 14
Joined: 21 Jun 2017, 08:22

Re: Switch between open Windows of the same type and same App

01 May 2019, 07:58

Nice script! Suggestion for improvement, add this ability for switching Windows 10 Explorer windows.
burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Switch between open Windows of the same type and same App

01 May 2019, 09:52

@JuanmaMenendez, thank you. This is very useful for me.
Regards,
burque505

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 140 guests