Welcome Guest! To enable all features please Login or Register.



Go to last post Go to first unread
#1 Posted : Monday, April 12, 2021 2:44:58 PM(UTC)

Rank: Administration


Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 926
United States
Location: Tampa, FL

Thanks: 21 times
Was thanked: 265 time(s) in 231 post(s)
This example is something I use to easily switch in and out of a full screen, multiple monitor, VMWare Workstation instance.

For work I have a dedicated VM which where I have all apps for work. This runs in full screen and spans multiple monitors.

But I run VMWare on my personal PC, so I like to be able to easily switch out (minimize) VMWare to do personal tasks (music, GMail, etc) and just as easily bring VMWare back up. So I have the same gesture (V) for S+ on my host (personal) and in the client (work VM) which do their respective tasks of taking me to the other.

To accomplish this, I leverage the FileSystemWatcher class to watch one file and look for any time it's been changed. For my VM, I have shared folders enabled, so the VM can see the C drive of the host. In the VM the gesture writes to a file on the host machine which the FileSystemWatcher raises an event and the script minimizes VMWare. In the host, the same gesture just finds and activates the VMWare window.

Host (main) PC

Global Actions > Load/Unload > Load script

// Only install in last script engine
if(__spEngineWrapper.Engine.Name == sp.EngineList().Last().Engine.Name)
    // Only create if it doesn't already exist
    if(sp.GetStoredObject("VMWareWatcher") != null)
        var configWatcher = new clr.System.IO.FileSystemWatcher();
        //Set the path to the target folder where the file will exist
        configWatcher.Path = "C:\\Temp\\";
        //Only watch this file, no others in the directory
        configWatcher.Filter = "VMWareSwitch.txt";
        //Only subscribe to file write operations
        configWatcher.NotifyFilter = clr.System.IO.NotifyFilters.LastWrite;
        //Create the event handler which is called when the file changes
        var configChangedEvent = configWatcher.Changed.connect(
            function (sender, fileChangedEvent) {
                    // Change to match your window title
                    sp.WindowFromClassOrTitle("", "Windows 10 x64 - VMware Workstation").Minimize();
        //Start the file watcher
        configWatcher.EnableRaisingEvents = true;
        //Store the file watcher and Changed event objects for any future reference needs
        sp.StoreObject("VMWareFileChangedEvent", configChangedEvent);
        sp.StoreObject("VMWareWatcher", configWatcher);

Action Script on Host to Activate VMWare
// Activate VMWare window
sp.WindowFromClassOrTitle("", "Windows 10 x64 - VMware Workstation").Activate();

// This is specific to my multiple monitor setup, if gesture occurs on left monitor,
// send Ctrl+G to grab input since VMWare onlys seems to do this on the primary screen
if(action.End.X < 0) {
    sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_G]);

Client (VMWare)

Action script
// Write text to the file that the host PC S+ watches and minimizes VMWare 
// when the file changes
File.WriteAllText("\\\\vmware-host\\Shared Folders\\C\\Temp\\VMWareSwitch.txt", "GO");

So I just draw a V and it will switch back and forth, to main desktop or VMWare, regardless of which workspace is the active one.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.