Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Move application to first available zone

Description
Use this script in conjunction with a "Window Created" Trigger rule for the application you want it to affect. You'll need to configure the X, Y, Width, and Height of each zone in the "positions" list starting on line 17, and the process name of the application on line 27.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
May 3, 2023
Date Last Modified
May 3, 2023

Scripted Function (Macro) Code

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

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
		// Set the X, Y, Width, Height of the positions here
		List<Rectangle> positions = new List<Rectangle>();
		positions.Add(new Rectangle(-1, 0, 963, 521));
		positions.Add(new Rectangle(960, 0, 963, 521));
		positions.Add(new Rectangle(-1, 521, 963, 521));
		positions.Add(new Rectangle(960, 520, 963, 521));
		positions.Add(new Rectangle(-964, 0, 963, 521));
		positions.Add(new Rectangle(-1927, 0, 963, 521));
		positions.Add(new Rectangle(-964, 520, 963, 521));
		positions.Add(new Rectangle(-1927, 520, 963, 521));
		
		// Set the process name of the application here
		String processName = "notepad.exe";
		
		// Check if there are any open windows at either position
		bool[] positionsOccupied = new bool[positions.Count];
		for (int i = 0; i < positions.Count; i++)		
		{
			positionsOccupied[i] = false;
		}
		
		foreach (IntPtr window in BFS.Window.GetVisibleWindowHandles())
		{
            if (BFS.Application.GetMainFileByWindow(window).ToLower().Contains(processName.ToLower()))
            {
                Rectangle bounds = BFS.Window.GetBounds(window);
				int j = 0;
				foreach (Rectangle position in positions)
				{
					if (bounds == position)
					{
						positionsOccupied[j] = true;
					}
					j++;
				}
            }
		}
		
		// Place the new window depending on where the open ones are
		int k = 0;
		foreach (bool positionOccupied in positionsOccupied)
		{
			if (!positionOccupied)
			{
				BFS.Window.SetSizeAndLocation(windowHandle, positions[k].X, positions[k].Y, positions[k].Width, positions[k].Height);
				break;
			}
			k++;
		}
	}
}