Skip to content

Instantly share code, notes, and snippets.

@chmouel
Last active October 1, 2024 18:33
Show Gist options
  • Save chmouel/83309f1f36a38b61fb177e8d9e8dd0df to your computer and use it in GitHub Desktop.
Save chmouel/83309f1f36a38b61fb177e8d9e8dd0df to your computer and use it in GitHub Desktop.
Focus or open msedge or windowsterminal on win+w or win+j
#Requires AutoHotkey v2.0
global previousWindow := ""
; Define a function to focus or open
FocusOrOpen(exe, runit) {
global previousWindow
edgeWindow := "ahk_exe " . exe
; Check if Microsoft Edge is already open
if WinExist(edgeWindow) {
if (WinActive(edgeWindow)) {
if previousWindow {
WinActivate(previousWindow)
previousWindow := ""
}
} else {
previousWindow := WinExist("A")
WinActivate(edgeWindow)
}
} else {
previousWindow := WinActive()
Run(runit)
WinWaitActive(edgeWindow)
}
}
#w::FocusOrOpen("msedge.exe", "msedge.exe")
#j::FocusOrOpen("WindowsTerminal.exe", "wt.exe")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment