You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. Since you suggested we share our functions, I'm using your VD class for a long time.
1000x of times a day I'm using shortcuts to switch to an app, like ALT+E for Edge, ALT+A for Agenda... etc
Whenever I'm using this shortcut I want to go to a specific window of the corresponding app, so I want the shortcut to either :
launch the app if not found
switch to the app (and virtual desktop) if found, and make it active and upfront
cycle between windows of this app if multiple are found (very useful for Edge, Notion...)
minimize the app if only 1 window exists (useful to quickly pop up and down the Agenda, Whatsapp, Slack apps...)
Here's my custom function based on your VD class :
; function based on VD._tryGetValidWindow; modified to return the list of all matching valid windows if mutliples are found; and to accept regextryGetValidWindow_list(wintitle, useRegEx:=false) {
bak_DetectHiddenWindows:=A_DetectHiddenWindows
bak_TitleMatchMode:=A_TitleMatchModeDetectHiddenWindows, onSetTitleMatchMode, 2if useRegEx {
SetTitleMatchMode, RegEx
}
WinGet, outHwndList, List, % wintitle
returnValue:=[]
loop % outHwndList {
theHwnd:=outHwndList%A_Index%+0
arr_success_pView_hWnd:=VD._isValidWindow(theHwnd)
pView:=arr_success_pView_hWnd[2]
if (pView) {
returnValue.push([arr_success_pView_hWnd[3], pView])
}
}
SetTitleMatchMode % bak_TitleMatchMode
DetectHiddenWindows % bak_DetectHiddenWindows
return returnValue
}
; Function based on VD.goToDesktopOfWindow; modified to switch between the list of active windows if many match,; and to minimize the window if there's only 1 window and it's already active; and to accept regexgoToDesktopOfWindow_cycleOrMinimize(wintitle, minimizeIfActive:=true, useRegEx:=false) {
; search for matching window
found:=tryGetValidWindow_list(wintitle, useRegEx)
nb_found:=found.Length()
if (nb_found==0) {
toolTip_custom("Not found, launching app") ; DEBUGreturn-1 ;for false
}
; We found at least 1 matching window
theHwnd:=found[1][1]
thePView:=found[1][2]
; select the window to activate if multiples are found :
activeHwnd := WinExist("A") ; An easy way to retrieve the unique ID of the active window ; keep the most recent (top) found window if it's not active ; or pick the bottom window if multiples are found and one is already activeif (nb_found > 1 and activeHwnd == theHwnd) {
theHwnd:=found[nb_found][1]
thePView:=found[nb_found][2]
}
; Switch desktop if needed
desktopNum_ofWindow:=VD._desktopNum_from_pView(thePView)
needSwitchDesktop:=(VD._desktopNum_from_pView(thePView) != VD.getCurrentDesktopNum())
if (needSwitchDesktop) {
VD.goToDesktopNum(desktopNum_ofWindow)
}
if (activeHwnd != theHwnd) {
; active window is not the targetedWinActivate, ahk_id %theHwnd%
}
if (activeHwnd == theHwnd and minimizeIfActive and not needSwitchDesktop) {
WinMinimize ; don't need to specify, it uses the last found window in WinExist
}
}
And here's how I use it :
!e:: ; === Edge === ; ; rename Edge workspace with "nav:" prefix in order to make those workspace windows appears in the shortcut
found := goToDesktopOfWindow_cycleOrMinimize("(.*Microsoft Edge.*|nav:.*)", true, true)
If (found == -1)
{
Run, microsoft-edge:
}
MoveMouseToCenterActiveWindow()
return
Thank you again for your work, and hope it can inspire others.
Cheers
The text was updated successfully, but these errors were encountered:
Hi. Since you suggested we share our functions, I'm using your VD class for a long time.
1000x of times a day I'm using shortcuts to switch to an app, like ALT+E for Edge, ALT+A for Agenda... etc
Whenever I'm using this shortcut I want to go to a specific window of the corresponding app, so I want the shortcut to either :
Here's my custom function based on your VD class :
And here's how I use it :
Thank you again for your work, and hope it can inspire others.
Cheers
The text was updated successfully, but these errors were encountered: