VD.ahk icon indicating copy to clipboard operation
VD.ahk copied to clipboard

WinExist in another virtual desktop

Open jdmarch opened this issue 11 months ago • 7 comments

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)

jdmarch avatar Mar 10 '24 23:03 jdmarch

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)
}

FuPeiJiang avatar Mar 11 '24 01:03 FuPeiJiang

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 avatar May 16 '24 08:05 Morgenkaff

@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)
}

FuPeiJiang avatar May 16 '24 08:05 FuPeiJiang

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 avatar May 22 '24 09:05 mariusmg

@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 avatar May 22 '24 14:05 FuPeiJiang

@FuPeiJiang

You're right, works fine with ahk_exe 👍

Thanks for suggestion and VD.ahk

mariusmg avatar May 23 '24 10:05 mariusmg

@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)
}

I've somehow overlooked both options. Works perfectly. Thanks!

Morgenkaff avatar May 23 '24 16:05 Morgenkaff