Last active
May 5, 2019 14:37
-
-
Save richardballard/93479558ffebe20116404a9d89a7f235 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
; This AutoHotkey script is to switch between open Windows of the same type and same App (.exe) | |
; The "type" checking is based on the App's Title convention that stipulates that the App name should be at the end of the Window title (Eg: New Document - Word ) | |
; It works well with regular Window Apps, Chrome Shortcuts and Chrome Apps | |
/* ; | |
***************************** | |
***** UTILITY FUNCTIONS ***** | |
***************************** | |
*/ | |
ExtractAppTitle(FullTitle) | |
{ | |
AppTitle := SubStr(FullTitle, InStr(FullTitle, " ", false, -1) + 1) | |
Return AppTitle | |
} | |
/* ; | |
*********************************** | |
***** SHORTCUTS CONFIGURATION ***** | |
*********************************** | |
*/ | |
; Alt + ` - Activate NEXT Window of same type (title checking) of the current APP | |
!`:: | |
WinGet, ActiveProcess, ProcessName, A | |
WinGet, OpenWindowsAmount, Count, ahk_exe %ActiveProcess% | |
If OpenWindowsAmount = 1 ; If only one Window exist, do nothing | |
Return | |
Else | |
{ | |
WinGetTitle, FullTitle, A | |
AppTitle := ExtractAppTitle(FullTitle) | |
SetTitleMatchMode, 2 | |
WinGet, WindowsWithSameTitleList, List, %AppTitle% | |
If WindowsWithSameTitleList > 1 ; If several Window of same type (title checking) exist | |
{ | |
WinActivate, % "ahk_id " WindowsWithSameTitleList%WindowsWithSameTitleList% ; Activate next Window | |
} | |
} | |
Return | |
; -------------- | |
; Functions | |
; -------------- | |
OpenOrShowAppBasedOnExeName(AppAddress) | |
{ | |
AppExeName := SubStr(AppAddress, InStr(AppAddress, "\", false, -1) + 1) | |
IfWinExist ahk_exe %AppExeName% | |
{ | |
IfWinActive | |
{ | |
WinMinimize | |
Return | |
} | |
else | |
{ | |
WinActivate | |
Return | |
} | |
} | |
else | |
{ | |
Run, %AppAddress%, UseErrorLevel | |
If ErrorLevel | |
{ | |
Msgbox, File %AppAddress% Not Found | |
Return | |
} | |
else | |
{ | |
WinWait, ahk_exe %AppExeName% | |
WinActivate ahk_exe %AppExeName% | |
Return | |
} | |
} | |
} | |
; AppTitle: Usually the word at the end of the app window title(Eg: in: "New Document - Word" will be "Word") | |
; AppModelUserID: A comprehensive guide on how to find the AppModelUserID of a windows store app can be found here: https://jcutrer.com/windows/find-aumid | |
OpenOrShowAppBasedOnAppModelUserID(AppTitle, AppModelUserID) | |
{ | |
SetTitleMatchMode, 2 | |
IfWinExist, %AppTitle% | |
{ | |
IfWinActive | |
{ | |
WinMinimize | |
Return | |
} | |
else | |
{ | |
WinActivateBottom %AppTitle% | |
} | |
} | |
else | |
{ | |
Run, shell:AppsFolder\%AppModelUserID%, UseErrorLevel | |
If ErrorLevel | |
{ | |
Msgbox, File %AppModelUserID% Not Found | |
Return | |
} | |
} | |
} | |
; -------------- | |
; Global hotkeys | |
; -------------- | |
; Command line | |
#c:: OpenOrShowAppBasedOnExeName("ConEmu64.exe") ; Win+C | |
#+c:: Run, *RunAs ConEmu64.exe ; Ctrl+Win+C (Run as admin) | |
; Music | |
#m:: OpenOrShowAppBasedOnExeName("%UserProfile%\AppData\Roaming\Spotify\Spotify.exe") ; Win+M | |
; Notes | |
#n:: OpenOrShowAppBasedOnExeName("%UserProfile%\AppData\Local\boost\Boostnote.exe") ; Win+N | |
; Password Manager | |
#p:: OpenOrShowAppBasedOnExeName("%UserProfile%\AppData\Roaming\Dashlane\Dashlane.exe") ; Win+P | |
; To do list | |
#t:: OpenOrShowAppBasedOnAppModelUserID("trello", "45273LiamForsyth.PawsforTrello_7pb5ddty8z1pa!trello") ; Win+T | |
; Web browser | |
#w:: OpenOrShowAppBasedOnExeName("brave.exe") ; Win+W |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment