ActivateOrLaunch(appName, appExe, appPath)
{
if WinExist("ahk_exe " . appExe)
{
WinActivate
}
else
{
SplashTextOn, , , Launching %appName%
Run, %appPath%
WinWait, ahk_exe %appExe%
SplashTextOff
}
}
; Hot string is Ctrl+;
; Then it reads the next two characters typed and, if a match is found, launches or activates the matching entry.
; Just keep chaining else ifs to add more programs.
; This is a sample of what I might use.
; There's a bug that I haven't bothered to fix: if the specified program / path can't be found, the splash text
; message stays up until reloading the running AHK script.
^`::
Input, TextEntry1, L1,{Esc}{Enter}{F1}{Down}{Up}
endKey = %ErrorLevel%
Input, TextEntry2, L1 T1,{Esc}{Enter}
timeout = %ErrorLevel%
entry = %TextEntry1%%TextEntry2%
if (entry = "sa")
{
WinActivate, ahk_exe slack.exe
}
else if (entry = "ss") {
WinActivate, ahk_exe Ssms.exe
return
}
else if (entry = "lp") {
ActivateOrLaunch("LINQPad", "LINQPad.exe", "C:\Program Files (x86)\LINQPad5\LINQPad.exe")
return
}
else if (entry = "bc") {
ActivateOrLaunch("Beyond Compare", "BCompare.exe", "C:\Program Files\Beyond Compare 4\BCompare.exe")
return
}