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?

Confirm

Are you sure?

User Image
Andy Newby89021
7 discussion posts
I've been trying to do this in Javascript, but it seems that the new window stuff doesn't let you stipulate a different screen, or let you do left/top negative poistions to "move" it to another screen. So I'm now trying to find a 3rd party marco/ script I can write that will move these windows on to different screens. The windows will be open, and I just want to have a way to do a certain key combination, and it will magicly move them between windows

My screen setup is:

Code

5   4
3   1   2


Screen 1 is the primary. What I want to do, is find all the chrome windows (I don't care if it includes the main one), and then split them off into x number per screen. I had a look at the existing macros / scripts, but couldn't find one that would work for me.

Is there an existing one? Or how hard is it to write them? I'm a perl/html/js programmer, so don't even know what language the marcos/scripts are written in :)

Thanks in advance!

Andy
Apr 27, 2024  • #1
Owen Muhlethaler (BFS)'s profile on WallpaperFusion.com
This script sounds like it will do what you're looking for: https://www.displayfusion.com/ScriptedFunctions/View/?ID=390c0c68-6dca-4614-b618-8f49a3dc5423

You can just copy and paste those lines for however many windows/monitors you want it to handle
Apr 29, 2024  • #2
User Image
Andy Newby89021
7 discussion posts
Thanks - that looks promising :) Is there a way to do it for existing chrome instances? i.e don't set a new one up, but find x instances of chrome (popups ideally, but can be the main window as well), and then move them around. The reason being, is that the URLs are not fixed (it will be a different URL every time). What I need to do is just "scatter" them across the screens :)

Thanks!

Andy
Apr 29, 2024  • #3
User Image
Andy Newby89021
7 discussion posts
I asked ChatGPT to write me something - and it came up with this:

Code

using System;
using System.Drawing;

using System.Collections.Generic;
using BinaryFortress.Windows;

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // Get all Chrome windows
        List<IntPtr> chromeWindows = BFS.Window.GetVisibleWindowHandlesByClassName("Chrome_WidgetWin_1");

        // Get the number of monitors
        int monitorCount = 3; // Adjust this to BFS.Monitor.GetMonitorCount() if dynamic assignment is preferred

        // Check if there are enough monitors
        if (BFS.Monitor.GetMonitorCount() < monitorCount)
        {
            BFS.Dialog.ShowMessageInfo("Not enough monitors. This script requires at least 3 monitors.");
            return;
        }

        // Loop through each Chrome window and move it to a different monitor
        for (int i = 0; i < chromeWindows.Count; i++)
        {
            // Calculate which monitor to move the window to
            int targetMonitor = i % monitorCount;BFS.

            // Get the bounds of the target monitor
            RECT monitorBounds = BFS.Monitor.GetMonitorBoundsByIndex(targetMonitor);

            // Move and size the window to fit the monitor
            BFS.Window.SetSizeAndLocation(chromeWindows[i], monitorBounds.Left, monitorBounds.Top, monitorBounds.Width, monitorBounds.Height);
        }

        // Show a message when complete
        BFS.Dialog.ShowMessageInfo("All Chrome instances have been moved and resized across " + monitorCount + " monitors.");
    }
}


I get quite a few errors though (and it doesn't run). I can't find any docs on how it should work so I can try and get it going?

Thanks

Andy
Apr 30, 2024  • #4
Owen Muhlethaler (BFS)'s profile on WallpaperFusion.com
Our Window Position Profiles will do that for you, as long as the match conditions don't change, and they are unique among each window. We have a guide on working with them here: https://www.displayfusion.com/HelpGuide/WindowPositionProfiles/
Apr 30, 2024  • #5
User Image
Andy Newby89021
7 discussion posts
Thanks, but that doesn't seem to work. I created it with the windows in the postion I wanted - and then opened up the same number of popups. They moved, but to the wrong position (all moved to screen 5, rather than where they should have been (spread out between screens)

BTW, the URLs will always change. Basically, I have a system I've written where I'm updating thousands listings on my website. Its a manual job (unfortunatly!), so what I do is open up a batch of them all at once (rather than clicking tons of times on our management tool for each listing). So what i need, is a way to position those. I wish browsers had the option to set different screen positions from the window.open :( would make my life a lot easier

I think a scripted function would be better, but just need to work out how to do that, as the code chatGPT offers doesn't seem to work. I seem to remember a while ago that you changed your API's, so maybe its using an older one?

Oh, and I think the reason the profile layout thing is failing, is due to it taking the last entry on the list of programs - and applying it to ALL the screens. i.e it seems to just say "oh, this is chrome... lets put everything here". This is why I think a script would be better :) (I tried and failed again to get one written, I get an error but can't paste it here as the debugger doesn't let you copy and paste, which seems an oversight)

Thanks
• Attachment [protected]: Screenshot 2024-05-01 063657.png [67,847 bytes]
May 1, 2024 (modified May 1, 2024)  • #6
User Image
Andy Newby89021
7 discussion posts
Quote:
This script sounds like it will do what you're looking for: https://www.displayfusion.com/ScriptedFunctions/View/?ID=390c0c68-6dca-4614-b618-8f49a3dc5423

You can just copy and paste those lines for however many windows/monitors you want it to handle


Eugh, this is doing my head in!!!!

Code

using System;
using System.Drawing;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
// using BinaryFortress.Windows;

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // Get all Chrome windows
        var processes = (System.Diagnostics.Process.GetProcessesByName("chrome"));

        // Get the number of monitors
        int monitorCount = 3; // Adjust this to BFS.Monitor.GetMonitorCount() if dynamic assignment is preferred

        BFS.General.LogText("monitor count: " +  monitorCount);

        for(int i = 0; i < processes.Length; i++) {
            Process proc = processes[i];

            // only run it when the title is Chrome_WidgetWin_1 (regex)
            if (Regex.IsMatch(proc.MainWindowTitle, "Chrome_WidgetWin_1")) {
                int targetMonitor = i % monitorCount;
                BFS.General.LogText("Do more... to screen " + targetMonitor);
                BFS.Window.MoveToMonitorMaximized(proc.MainWindowHandle, (uint)targetMonitor);
            }
        }

     
        // Show a message when complete
        BFS.Dialog.ShowMessageInfo("All Chrome instances have been moved and resized across " + monitorCount + " monitors.");
    }
}


I get:

Code

Line    Char    Description
30      51      Argument 1: cannot convert from 'int' to 'uint'
30      74      Argument 2: cannot convert from 'uint' to 'int'
0       0       Error: Compile failed. [System.Exception]


This has to be one of the most frustrating programming languages I've ever worked with :'(
May 2, 2024  • #7
User Image
Andy Newby89021
7 discussion posts
Happy I worked it out, but not the fact I had to spend almost a week doing it :(

Code

using System;
using System.Drawing;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Text;

public static class DisplayFusionFunction
{
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);

    private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

    // Keep track of which monitor to use next
    private static int nextMonitorIndex = 1;  // Start with 1 if DisplayFusion uses 1-based index

    public static void Run(IntPtr windowHandle)
    {
        // Enumerate all windows
        EnumChildWindows(IntPtr.Zero, new EnumWindowsProc(EnumWindowCallback), IntPtr.Zero);
    }

    private static bool EnumWindowCallback(IntPtr hWnd, IntPtr lParam)
    {
        StringBuilder windowText = new StringBuilder(256);
        if (GetWindowText(hWnd, windowText, 256) > 0)
        {
            // Specify the window title that you are interested in
            if (windowText.ToString().Contains("Suggest A Change"))
            {
                // Move the window to the next monitor and maximize it
                BFS.Window.MoveToMonitorMaximized((uint)nextMonitorIndex, hWnd);

                // Update the monitor index, cycling through 1-5
                nextMonitorIndex = (nextMonitorIndex % 5) + 1;
            }
        }
        return true; // Continue enumeration
    }
}
May 3, 2024  • #8
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Glad to hear you were able to get it working, coding can be frustrating sometimes! I've also just added an example function that does something similar to the repository if you wanted to try it out: https://www.displayfusion.com/ScriptedFunctions/View/?ID=018f3ff3-97b3-7505-99db-6ebaa0d72abe
May 3, 2024  • #9
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)