Swap All Windows Between Displays

Looking to create a macro that would swap all the windows in one display with another. The displays are the same size.

Just looking for advice before I dive in and try to create something from scratch of if anything already exists.

Thinking I’ll have to save the window name and locations and then tell them to move to the same position on the other display?

For a very similar example, see:

MACRO: Move ALL Windows to Primary Screen

1 Like

Hey Rusty,

Welcome to the forum!   :smile:

Looks like @JMichaelTX has you covered.

-Chris

Thanks. Going to dive into the script looks like a great starting point.

But I’m getting errors trying to run it. Is these a newer version I missed in that thread?

Please post the EXACT error you are getting.
Are you running my Macro without any changes?
If you made changes, please post your macro.

See How to upload your macro. Instructions for uploading to an existing post are just below the main instruction.

No changes yet. Sorry I knew you would need it but was on a different device.

[ERROR]

Can’t get origin of {{0.0, 0.0}, {3440.0, 1415.0}}.

SCRIPT: Move Windows to Main Screen Ver: 2.0

Error Number: -1728

For some unknown reason Apple chose to change how they report the screen properties, which caused this error.
I just updated the Macro with a fix.
It runs fine with Keyboard Maestro 9.2 on macOS 10.14.6 (Mojave).

Since the macro is really just a wrapper for an AppleScript, it may not help you unless you speak AppleScript. When I get some time I'll take a look at allowing the user to specify which screen to move the windows to.

Here's a script to get the coordinates of a specified screen. Maybe you can combine this with the script in the Macro to get what you want.

AppleScript to Get Screen Coordinates

property ptyScriptName : "Get Screen Coordinates"
property ptyScriptVer : "1.0"
property ptyScriptDate : "2021-02-24"
property ptyScriptAuthor : "JMichaelTX"

### Required:  macOS Sierra+    Tested In: macOS Mojave 10.14.6+

use AppleScript version "2.5"
use scripting additions
use framework "Foundation" -- Required for all ASObjC commands

set screenCoord to my getScreenFrame("Full", 2)
-->{2560.0, 0.0, 2560.0, 1440.0}

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on getScreenFrame(pFullOrVisible, pScreenNum)
  (*  VER: 1.0    2021-02-24
-------------------------------------------------------------------------------
  PURPOSE:  Get Screen Coordinates of Specified Screen
  PARAMETERS:
    β€’ pFullOrVisible    ┃ text      ┃ Must be "Full" or "Visible"
    β€’ pScreenNum          ┃ integer  ┃ Screen Number, where Main Screen = 1

  RETURNS:                  ┃ list      ┃ Screen Coordinates Left, Top, Width, Height
  AUTHOR:  JMichaelTX
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
*)
  
  set frameType to "frame"
  if (pFullOrVisible = "Visible") then set frameType to "visibleFrame"
  set screenFrameList to current application's NSScreen's screens()'s valueForKey:(frameType)
  
  set screenFrame to item pScreenNum of (screenFrameList as list)
  set screenFrame to (item 1 of screenFrame) & (item 2 of screenFrame)
  
  return screenFrame
  
end getScreenFrame
--~~~~~~~~~~~~~~~ END OF handler getScreenFrame ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@Rusty, let us know if you need more help.