AutoHotkey: Launch or Switch App

By Xah Lee. Date: . Last updated: .

Set Key to Launch App or Switch Window

set a key that launches a browser, but if it is already running, just switch to it.

#Requires AutoHotkey v2.0

; launch or switch to Firefox
f10:: {
    if ProcessExist("firefox.exe") {
        ; Switch to an existing Firefox window
        WinActivate("ahk_exe firefox.exe")
    } else {
        ; Launch Firefox if not running
        Run("firefox.exe")
    }
}
; AutoHotkey version 1.x

; launch or switch to Firefox
; http://xahlee.info/mswin/autohotkey_switch_launch_app.html
; Version 2021-02-21 2022-01-19
launchOrSwitchFirefox()
{
if WinExist("ahk_class MozillaWindowClass")
{
WinActivateBottom, ahk_class MozillaWindowClass
}
Else
{
 Run "C:\Program Files\Mozilla Firefox\firefox.exe"
}
Return
}

F8::launchOrSwitchFirefox()

Use Taskbar Key

Pin the apps you want to the taskbar. Microsoft Windows Taskbar

#Requires AutoHotkey v2.0

; make F1 send Win+1
F1::Send "#1"

; make F2 send Win+2
F2::Send "#2"

AutoHotkey, Switch Window