Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinExist in another virtual desktop #68

Open
jdmarch opened this issue Mar 10, 2024 · 7 comments
Open

WinExist in another virtual desktop #68

jdmarch opened this issue Mar 10, 2024 · 7 comments

Comments

@jdmarch
Copy link

jdmarch commented Mar 10, 2024

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)

@FuPeiJiang
Copy link
Owner

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

@Morgenkaff
Copy link

Morgenkaff commented May 16, 2024

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.

@FuPeiJiang
Copy link
Owner

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

@mariusmg
Copy link

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.

@FuPeiJiang
Copy link
Owner

@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 ?

@mariusmg
Copy link

@FuPeiJiang

You're right, works fine with ahk_exe 👍

Thanks for suggestion and VD.ahk

@Morgenkaff
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants