Skip to content

Instantly share code, notes, and snippets.

@Xainey
Created March 21, 2016 14:44
Show Gist options
  • Save Xainey/eaec3344461d7229eb86 to your computer and use it in GitHub Desktop.
Save Xainey/eaec3344461d7229eb86 to your computer and use it in GitHub Desktop.
Open, maximize, or minimize a program with a hotkey
; Open / Bring to Front / Minimize Program
; For hotkey syntax - https://autohotkey.com/docs/Hotkeys.htm
; Example Alt-C to open Conemu
!c::OpenProgram("c:\PortableApps\ConEmu64.exe")
ToggleWindow(TheWindowTitle)
{
SetTitleMatchMode,2
DetectHiddenWindows, Off
IfWinActive, %TheWindowTitle%
{
WinMinimize, %TheWindowTitle%
}
Else
{
IfWinExist, %TheWindowTitle%
WinActivate
Else
{
DetectHiddenWindows, On
IfWinExist, %TheWindowTitle%
{
WinShow
WinActivate
}
}
}
}
ToggleWindowPID(PID)
{
IfWinActive ahk_pid %PID%
{
WinMinimize ahk_pid %PID%
}
Else
{
IfWinExist ahk_pid %PID%
{
WinActivate
WinMaximize
}
}
}
OpenProgram(TheProgram)
{
SplitPath, TheProgram, fileName
executable := fileName
Process, Exist, %executable%
If Not ErrorLevel
{
; For auto credentials
; RunAs, username, password, dnet.domain
Run, %TheProgram%
}
If (ErrorLevel != 0)
{
ToggleWindowPID(ErrorLevel)
ToggleWindow(executable)
}
Return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment