Created
March 21, 2016 14:44
-
-
Save Xainey/eaec3344461d7229eb86 to your computer and use it in GitHub Desktop.
Open, maximize, or minimize a program with a hotkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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