Last active
April 8, 2019 13:32
-
-
Save realchrisolin/fb10b20c832acb7e54605980afd14836 to your computer and use it in GitHub Desktop.
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
; =========================================================================== | |
; Run a program or switch to it if already running. | |
; Target - Program to run. E.g. Calc.exe or C:\Progs\Bobo.exe | |
; WinTitle - Optional title of the window to activate. Programs like | |
; MS Outlook might have multiple windows open (main window and email | |
; windows). This parm allows activating a specific window. | |
; Use RunOrActivateMultiParam() for applications that have multiple execution | |
; parameters when RunOrActivate() doesn't work | |
; =========================================================================== | |
; change this to your home directory path | |
SetWorkingDir = "C:\Users\colin" | |
RunOrActivate(Target, WinTitle = "", Parameters = "") | |
{ | |
; Get the filename without a path | |
SplitPath, Target, TargetNameOnly | |
Process, Exist, %TargetNameOnly% | |
If ErrorLevel > 0 | |
PID = %ErrorLevel% | |
Else | |
Run, %Target% "%Parameters%", , , PID | |
; At least one app (Seapine TestTrack wouldn't always become the active | |
; window after using Run), so we always force a window activate. | |
; Activate by title if given, otherwise use PID. | |
If WinTitle <> | |
{ | |
SetTitleMatchMode, 2 | |
WinWait, %WinTitle%, , 3 | |
TrayTip, , Activating Window Title "%WinTitle%" (%TargetNameOnly%) | |
WinActivate, %WinTitle% | |
} | |
Else | |
{ | |
WinWait, ahk_pid %PID%, , 3 | |
TrayTip, , Activating PID %PID% (%TargetNameOnly%) | |
WinActivate, ahk_pid %PID% | |
} | |
SetTimer, RunOrActivateTrayTipOff, 1 | |
} | |
RunOrActivateMultiParam(Target, WinTitle = "", Param1 = "", Param2 = "", Param3 = "") | |
{ | |
; Get the filename without a path | |
SplitPath, Target, TargetNameOnly | |
Process, Exist, %TargetNameOnly% | |
If ErrorLevel > 0 | |
PID = %ErrorLevel% | |
Else | |
Run, %Target% "%Param1%" "%Param2%" "%Param3%", , , PID | |
; At least one app (Seapine TestTrack wouldn't always become the active | |
; window after using Run), so we always force a window activate. | |
; Activate by title if given, otherwise use PID. | |
If WinTitle <> | |
{ | |
SetTitleMatchMode, 2 | |
WinWait, %WinTitle%, , 3 | |
TrayTip, , Activating Window Title "%WinTitle%" (%TargetNameOnly%) | |
WinActivate, %WinTitle% | |
} | |
Else | |
{ | |
WinWait, ahk_pid %PID%, , 3 | |
TrayTip, , Activating PID %PID% (%TargetNameOnly%) | |
WinActivate, ahk_pid %PID% | |
} | |
SetTimer, RunOrActivateTrayTipOff, 1 | |
} | |
; Turn off the tray tip | |
RunOrActivateTrayTipOff: | |
SetTimer, RunOrActivateTrayTipOff, off | |
TrayTip | |
Return | |
;Keybinds | |
F12::RunOrActivateMultiParam("C:\Users\colin\AppData\Local\wsltty\bin\mintty.exe","", "--WSL=WLinux", "--configdir=C:\Users\colin\AppData\Roaming\wsltty'", "-~") | |
; Example uses... | |
;F12::RunOrActivate("C:\cygwin64\bin\mintty.exe","","-") | |
;^F11::RunOrActivate("C:\Program Files\Mozilla Firefox\firefox.exe") | |
;NumpadDown::RunOrActivate("C:\Program Files\Internet Explorer\iexplore.exe") | |
;NumpadPgDn::RunOrActivate("C:\Program Files\Notepad++\notepad++.exe") | |
;NumpadRight::RunOrActivate("C:\Program Files\Pidgin\pidgin.exe", "cevista") | |
; Outlook can have multiple child windows, so specify which window to activate | |
;NumpadClear::RunOrActivate("C:\Program Files\Microsoft Office\OFFICE12\OUTLOOK.EXE","Microsoft Outlook") | |
;Minimize/maximize active window | |
;^Down::WinMinimize, A | |
;^Up::WinRestore, A | |
;^+Up::WinMaximize, A | |
;!.::Send {Volume_Mute} | |
;^+Insert::Send {Media_Play_Pause} | |
;^+Up::Send {Volume_Up} | |
;^+Down::Send {Volume_Down} | |
;^+Left::Send {Media_Prev} | |
;^+Right::Send {Media_Next} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment