AutoHotKey v2 cycle through file explorer windows

I’ve an original hotkey – ctrl+ Shift + A for cycling through File Explorer open window instances that I got from this video of Taran’s years ago, and love using it.

I’ve also started to play with AutoHotKey V2 and am trying to adapt scripts from v1 to v2. I started by trying to acvtivate some python scripts using AutoHotKey v2 (a separate post) and wanted to extend it to popular scripts in v1 that I use.

I came across this video yesterday by the Automator about Teran’s script adapted to v2 for general programs but it didn’t apply to File Explorer. They also demonstrated it but didn’t give the code so I used powerToys ‘Text Extractor” to grab the code off the screen.

I spent a morning trying to get the script to work, and couldn’t, but while exploring through the v2 documentation I did see a reference to the File Explorer setup on this page under the ahk_group (Window Group) subheading and after using it in the code I was able to get it to work as well as the original v1 script. Here it is :

#Requires AutoHotkey v2.0
#SingleInstance force

AppsKey:: runThing()

GroupAdd "Explorer", "ahk_class CabinetWClass"	
if not WinExist("ahk_class CabinetWClass")
	Run 'explorer.exe'
	Winwait "ahk_exe explorer.exe"
	GroupActivate "Explorer", 'R'

End comment

I was really please with getting it to work finally. It was a frustrating process and only because I came across the documentation for hk_group (Window Group) did I finally get it to work.

I may adapt it for BIM work in the future where I may have a couple of open projects that I need to cycle through, but generally I only have one instance of other programs open at one time.