VD.ahk
VD.ahk copied to clipboard
WinExist in another virtual desktop
Use case: It would be great to have a hotkey which checks whether a specific app (window) is open in any Virtual Desktop, and if it is, activates it in its already-existing desktop. If it does not yet exist, I would open it in the current desktop, but YMMV. Thanks! (Win 11)
what do you mean ? can you write pseudocode ? 3 possibilities I can think of: 1)
if (VD.WinExistInDesktopNum(winTitle,desktopNum:=2)) {
WinActivate(winTitle)
} else {
Run(command)
}
2)
if (VD.WinExistInAnyDesktopNum(winTitle) {
WinActivate(winTitle)
} else {
Run(command)
}
3)
if (VD.WinExistInDesktopNum(winTitle,desktopNum:=2)) {
WinActivate(winTitle)
} else {
VD.MoveWindowToCurrentDesktop(winTitle)
WinActivate(winTitle)
}
Personally I would like
if (VD.WinExistInAnyDesktopNum(winTitle) {
WinActivate(winTitle)
} else {
Run(command)
}
and
if (VD.WinExistInNotCurrentDesktop(winTitle) {
WinActivate(winTitle)
} else {
Run(command)
}
Unless there is is another way to know if a given window exists, and then move it to current desktop.
@Morgenkaff
WinExist
with DetectHiddenWindows 1
will search in all VD
DetectHiddenWindows 1
if (WinExist(winTitle)) {
VD.MoveWindowToCurrentDesktop(winTitle)
} else {
Run(command)
}
getDesktopNumOfWindow
probably searches in all VD too
if (VD.getDesktopNumOfWindow(winTitle)!==VD.getCurrentDesktopNum()) {
VD.MoveWindowToCurrentDesktop(winTitle)
} else {
Run(command)
}
Hello,
Would it be possible to also add a version of MoveWindowToCurrentDesktop which supports PID ? On a hotkey shortcut, i want to check if a specific process exists then move the window to current virtual desktop and then activate it :
VD.MoveWindowToCurrentDesktop("ahk_pid" PID)
WinActivate("ahk_pid" PID)
Right now this seems to only work with window titles.
@mariusmg
VD.MoveWindowToCurrentDesktop("ahk_pid" PID)
WinActivate("ahk_pid" PID)
does this code work for you ? if yes, I don't know what you're asking, because this is by PID if no, what is the program that it doesn't work for ? because it will probably work for notepad.exe
On a hotkey shortcut, i want to check if a specific process exists then move the window to current virtual desktop and then activate it :
if (VD.getDesktopNumOfWindow("ahk_exe notepad.exe")!==VD.getCurrentDesktopNum()) {
VD.MoveWindowToCurrentDesktop("ahk_exe notepad.exe")
}
do you really need PID when you can use ahk_exe ?
@FuPeiJiang
You're right, works fine with ahk_exe 👍
Thanks for suggestion and VD.ahk
@Morgenkaff
WinExist
withDetectHiddenWindows 1
will search in all VDDetectHiddenWindows 1 if (WinExist(winTitle)) { VD.MoveWindowToCurrentDesktop(winTitle) } else { Run(command) }
getDesktopNumOfWindow
probably searches in all VD tooif (VD.getDesktopNumOfWindow(winTitle)!==VD.getCurrentDesktopNum()) { VD.MoveWindowToCurrentDesktop(winTitle) } else { Run(command) }
I've somehow overlooked both options. Works perfectly. Thanks!