Skip to content

Instantly share code, notes, and snippets.

@kkoziarski
Last active May 26, 2021 06:43
Show Gist options
  • Save kkoziarski/e3d2023056fcead468911124f219889b to your computer and use it in GitHub Desktop.
Save kkoziarski/e3d2023056fcead468911124f219889b to your computer and use it in GitHub Desktop.
AutoHotkey (AHK) - open programs
SwitchToWindowsTerminal()
{
windowHandleId := WinExist("ahk_exe WindowsTerminal.exe")
windowExistsAlready := windowHandleId > 0
; If the Windows Terminal is already open, determine if we should put it in focus or minimize it.
if (windowExistsAlready = true)
{
activeWindowHandleId := WinExist("A")
windowIsAlreadyActive := activeWindowHandleId == windowHandleId
if (windowIsAlreadyActive)
{
; Minimize the window.
WinMinimize, "ahk_id %windowHandleId%"
}
else
{
; Put the window in focus.
WinActivate, "ahk_id %windowHandleId%"
WinShow, "ahk_id %windowHandleId%"
}
}
; Else it's not already open, so launch it.
else
{
Run wt
}
}
; Hotkey to use Win+Q to launch/restore the Windows Terminal.
#q::SwitchToWindowsTerminal()
SwitchToKeePassXC()
{
windowHandleId := WinExist("ahk_exe KeePassXC.exe")
windowExistsAlready := windowHandleId > 0
; If the KeePassXC is already open, determine if we should put it in focus or minimize it.
if (windowExistsAlready = true)
{
activeWindowHandleId := WinExist("A")
windowIsAlreadyActive := activeWindowHandleId == windowHandleId
if (windowIsAlreadyActive)
{
; Minimize the window.
WinMinimize, "ahk_id %windowHandleId%"
}
else
{
; Put the window in focus.
WinActivate, "ahk_id %windowHandleId%"
WinShow, "ahk_id %windowHandleId%"
}
}
; Else it's not already open, so launch it.
else
{
EnvGet, ProgramFiles32, ProgramFiles(x86)
EnvGet, ProgramFiles64, ProgramFiles
if (!ProgramFiles32)
ProgramFiles32 := ProgramFiles64
Run % ProgramFiles64 . "\KeePassXC\KeePassXC.exe"
}
}
; Run/show/hide KeePassXC using Win+K
#K::SwitchToKeePassXC()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment