StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
File Watcher to Switch and and out of VMWare
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 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) PCGlobal Actions > Load/Unload > Load script Code:// 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) {
try
{
// Change to match your window title
sp.WindowFromClassOrTitle("", "Windows 10 x64 - VMware Workstation").Minimize();
}
catch{}
}
);
//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 VMWareCode:// 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.Sleep(50);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_G]);
}
Client (VMWare)Action scriptCode:// 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.
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
File Watcher to Switch and and out of VMWare
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.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close