Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Distribute all open Google Chrome windows between all monitors

Description
This script will find all open Google Chrome windows, and will move them all to their own monitor and maximize. If there are more Chrome windows than monitors, it will start back at the beginning of the monitor list and keep distributing the windows.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
15d ago
Date Last Modified
15d ago

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Collections.Generic;

public static class DisplayFusionFunction
{
	public static void Run()
	{
		// Initialize the list
		var allChromeWindows = new List<IntPtr>();
		
		// Loop through all open windows and add Chrome windows to the list
		foreach (IntPtr window in BFS.Window.GetVisibleAndMinimizedWindowHandles())
		{
			if (BFS.Window.GetText(window).EndsWith("Google Chrome"))
			{
				allChromeWindows.Add(window);
			}
		}
		
		// Loop through the available monitors and move the windows to them
		int i = 0;
		for (int n = 0; n < BFS.Monitor.GetMonitorIDs().Length; n++)
		{
			BFS.Window.MoveToMonitorMaximized(BFS.Monitor.GetMonitorIDs()[n], allChromeWindows[i]);
			if ((allChromeWindows.Count - 1) == i)
			{
				// If we got here, we've moved all of the open windows
				return;	
			}
			i++;
			if (i == BFS.Monitor.GetMonitorIDs().Length)
			{
				// If we got here, there were more windows than monitors, so we reset the index on the monitors array
				n = -1;
			}
		}
	}
}