Git Product home page Git Product logo

Comments (10)

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024

let me rephrase / did I understand correctly ?

context:
you are in VD2
got:
you are moved to VD1, OneNote is started in VD1
want:
you stay in VD2, OneNote is started in VD2

from vd.ahk.

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024

if OneNote is changing your virtual desktop, I can't prevent it
I can save your current virtual desktop
start OneNote
move back to saved virtual desktop, move OneNote to saved virtual desktop

though it is pretty much impossible since Start is by PID, a PID can have 2 windows,
a PID can just inform the other PID, and quit itself, while the other PID creates another window
how would you know from the PID you started, that this newly created window (on a different existing PID) was the result of it?
you can only check if another window of certain wintitle or processName was created, the newly created one must be it
wait, get WinTitle, get PID, var map1 map[hwnd]bool=get all windows of that PID, Start, get all windows of that PID, newly created windows in this timespan are the ones you caused.

from vd.ahk.

llinfeng avatar llinfeng commented on July 27, 2024

Ha, to clarify, here are two things I had in mind when opening this issue:

  1. As you said, when launching OneNote specifically, it helps to keep it in the current virtual desktop and switching back to the current desktop if VD-switching happens unexpectedly;
  2. Further, it may help to start a window in a "hidden" VD, by literally "sending the window to the destination VD". This helps to create an easy-to-use launcher script, that populates all virtual desktops with the programs needed in that destination.

Towards the end of your most recent post, it looks like you found a way to identify the new OneNote window? That's great!

from vd.ahk.

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024

thanks for the use cases 1. and 2., allows me to write functions based on use case, instead of functionality : Launch a program at the current desktop, which I would optimize wrongly, idk, maybe it's even better to have both functionality and use case


@llinfeng
test https://github.com/FuPeiJiang/VD.ahk/tree/run_in_VD

run in VD.ahk, run in VD lock.ahk, VD.Run_lock_VD name to be (maybe) redecided

I used https://chris.dziemborowicz.com/apps/hourglass/ to test, you should test using OneNote (which I didn't want to install)

from vd.ahk.

llinfeng avatar llinfeng commented on July 27, 2024

@FuPeiJiang I tested the syntax in run in VD.ahk and it worked well for launching and sending gvim.exe, for example. Though, could you explain what is the VD.Run_lock_VD function in run in VD lock.ahk intended for?
In an effort of trying to make sense from the following line with the "lock" function - is it meant to keep the focus at VD 2, and launch a new window in VD 3? (Or, to flip it, to keep the focus at VD 3, and launch a new window in VD 2?)

VD.Run_lock_VD("""C:\Program Files (x86)\Hourglass\Hourglass.exe""","","","","Hourglass.exe",2,3)

For this "OneNote for Windows 10" app, nope, all windows were opened in the current virtual desktop, with nothing forwarded to the intended destination. Here is the window information for those OneNote windows in case it may help us get dispatched to the intended VD.

---------------------------
Warning
---------------------------
Paperless ‎- OneNote for Windows 10 
ahk_class ApplicationFrameWindow 
ahk_exe ApplicationFrameHost.exe 
hostname AW-R5
NumMonitor: 6, 2.666666 
PrimaryMonintor: 1200x1920
---------------------------
OK   
---------------------------

from vd.ahk.

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024

it's to launch a new window in VD 2, and set focus at VD 3

window_desktopNum, your_desktopNum

VD.ahk/_VD.ahk

Line 680 in c2a7e4b

Run_lock_VD(Target, WorkingDir, this_titleName, this_class, this_processName, window_desktopNum, your_desktopNum) {


for OneNote

Paperless ‎- OneNote for Windows 10
ahk_class ApplicationFrameWindow
ahk_exe ApplicationFrameHost.exe

can you send me full script that didn't work ?

if you did it like this, I don't think it will work

VD.Run_lock_VD("""OneNote.exe""","","Paperless ‎- OneNote for Windows 10","ApplicationFrameWindow","ApplicationFrameHost.exe",2,VD.getCurrentDesktopNum())

from where can I install your version of OneNote ?
from Microsoft Store ? https://apps.microsoft.com/store/detail/onenote/9WZDNCRFHVJL

from vd.ahk.

llinfeng avatar llinfeng commented on July 27, 2024

it's to launch a new window in VD 2, and set focus at VD 3

To make the variable names self-explanatory, how about window_desktopNum -> new_window_desktopNum and current_desktopNum? (I assume the intention is to keep the focus "local" while sending windows around. Then, it helps to use a wildcard symbol/number(0) to indicate the current desktop.)


Here is the full script that opened four OneNote windows in the current desktop. These UWP apps are hard to run direclty through Run command. For now, the only method I know is to first go to shell:AppsFolder using the Windows Run window, create a desktop shortcut for OenNote, and then, feed the link's path to the Run command.

Folded script
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines -1
#KeyHistory 0

#Include ..\VD.ahk

VD.startShellMessage()
VD.Run("""c:\users\llinfeng\Desktop\OneNote for Windows 10 - Shortcut.lnk""","","","","",1)
VD.Run("""c:\users\llinfeng\Desktop\OneNote for Windows 10 - Shortcut.lnk""","","","","",2)
VD.Run("""c:\users\llinfeng\Desktop\OneNote for Windows 10 - Shortcut.lnk""","","","","",3)
VD.Run("""c:\users\llinfeng\Desktop\OneNote for Windows 10 - Shortcut.lnk""","","","","",4)
return

f3::Exitapp

And, yes, the OneNote app I use most often is the free one from the Microsoft Store as you linked. It does the best job of syncing, where the thing from Office subscription would run into sync issues very frequently for me. Here is another script where I was trying to see if I can dispatch 4 onenote.exe windows to four virtual desktops. Upon running the script, only one onenote.exe instance is opened.

Folded script
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines -1
#KeyHistory 0

#Include ..\VD.ahk

VD.startShellMessage()
VD.Run("""C:\Program Files\Microsoft Office\root\Office16\ONENOTE.EXE""","","","","",1)
VD.Run("""C:\Program Files\Microsoft Office\root\Office16\ONENOTE.EXE""","","","","",2)
VD.Run("""C:\Program Files\Microsoft Office\root\Office16\ONENOTE.EXE""","","","","",3)
VD.Run("""C:\Program Files\Microsoft Office\root\Office16\ONENOTE.EXE""","","","","",4)


return

f3::Exitapp

Per its current state, VD.Run() is doing a great job. I assume it should work for normal windowed applications that are launched by running an executable file. Though, why both versions of OneNote are behaving as such, I don't have a good understanding yet. They do have a few things in common - it is hard to launch, and would fail to sync sometimes. Though, on the good part - they both offer an infinite canvas for scribbling with a digitizer (pen), and they are both helpful for annotating screenshots for snippets of code for ideation purposes.

from vd.ahk.

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024

VD.startShellMessage()
VD.goToDesktopNum(1)
;assume no OneNote window exists
;first window needs 5 seconds to ready
Run % "shell:AppsFolder\Microsoft.Office.OneNote_8wekyb3d8bbwe!microsoft.onenoteim"
Sleep 5000 ;subsequent runs will be ignored without waiting 5000ms
VD.Run("shell:AppsFolder\Microsoft.Office.OneNote_8wekyb3d8bbwe!microsoft.onenoteim","","OneNote for Windows 10","ApplicationFrameWindow","ApplicationFrameHost.exe",2)
VD.Run("shell:AppsFolder\Microsoft.Office.OneNote_8wekyb3d8bbwe!microsoft.onenoteim","","OneNote for Windows 10","ApplicationFrameWindow","ApplicationFrameHost.exe",3)

this is the best I could do..

remember to update branch https://github.com/FuPeiJiang/VD.ahk/tree/run_in_VD before running

from vd.ahk.

llinfeng avatar llinfeng commented on July 27, 2024

Fantastic. The example you give works great. It is very thoughtful that you switch to VD1 and launch the first OneNote window there.

Question: what does VD.startShellMessage() do? Without it, it looks like all OneNote windows are opened in the active virtual desktop.

from vd.ahk.

llinfeng avatar llinfeng commented on July 27, 2024

@FuPeiJiang Will you merge these back to the main branch? I assume it is class_VD?

It is a great pleasure to find this repo, and I'm planning to stay up-to-date as much as I can :)

from vd.ahk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.