If WindowName is at position 1 Then

I need to make a position switcher between two apps.

If Application A is at Position 1 and Application B is at Position 2, then move Application A to Position 2 and Application B to Position 1.

If Application B is at Position 1 and Application a is at Position 2, then move Application B to Position 2 and Application A to Position 1.

That's interesting. I like this problem. Although I need clarification on quite a few things. First, do you want the two apps to inherit the other app's size, or just the other app's position? (You only said position.) Second, is "App A" and "App B" always the same app, and can you tell us the names of the apps, or do you want the macro to work on any app? (If so, how does the user specify which apps to work on?) Third, are you able to guarantee that the size of each app is larger than the minimum size of the other app? (Many apps have minimum window sizes, and those differ from app to app.) Fourth, are the values of "Position 1" and "Position 2" fixed constants? Are you able to give us those constants? And fifth, do those constants include the size of the windows or just their upper left corner position?

Sixth, and this is a big one, most apps can have multiple windows open (including zero windows.) This raises some questions too. I think you may need to rephrase your question and replace the word "App" with the word "window." That's because apps don't really have any position at all... it's their windows that have positions. Or perhaps you should tell us exactly which apps you are trying to work with here.

Seventh, I'm not sure what your "If" conditions are really doing to solve your problem. It may be much simpler to just swap the positions and sizes of two windows, regardless of where they are.

Lastly, KM's ability to Move and Resize windows has limitations based on macOS's bad behaviour when it comes to moving windows. Any solution we write for you might (I said might) not work properly, and that would be the fault of macOS, not our macros. It may depend on things like the speed of your Mac, which of course we cannot test for.

I decided to go ahead and make a macro that does something similar to your request. It doesn't do the exact thing that you requested, but it does something similar. You can either download my macro and adapt it to your needs, or you can answer my questions so that I can help you further.

What this macro does is rotate all the windows of the Finder app into the location of the next window in the Finder app. It's cool, but it's slow because the Move and Resize window action is slow. So if you've got 5 windows open it will probably take 5 seconds to rotate them, which is not particularly satisfying. It first validates that there are at least 2 windows open, because if you have 0 or 1 window(s) open, there's obviously nothing to do.

I'll be honest... there's one action in this macro that surprises me that it works at all. I can't explain how it works, but it does. So I hope you don't ask me about it. :slight_smile:

Swap-Rotate Multiple Window positions in Finder Macro (v11.0.4)

Swap-Rotate Multiple Window positions in Finder.kmmacros (8.3 KB)

1 Like

Thanks! This is great and I can definitely use this. But I was trying to do something different so let me clarify it by answering your questions.

  1. I only open one window per app. App 1 Window 1 (Discord - We use discord for our work). App 2 Window 1 (Notion - Where I organize all of my tasks).
  2. I assigned both apps on a vertically stacked monitor with different monitor sizes. So the usual thing is Discord is on the top screen, while I work on notion on my main screen. They are both open full screen.
  3. I just need a macro to swap their screens and put them both in full screen mode.
  4. If it helps, I use rectangle pro to move the windows and put them in full screen. I have a keyboard shortcut to put them to a specific screen in full screen mode. So what I really just need is actually to identify which app window is on the top screen and main screen.
  5. If Discord is on the top screen and Notion is on the main screen, then move Discord to the main screen and Notion to the top screen and put them in full screen. /// If Notion is on the top screen and Discord is on the main screen, put Discord on the top screen and Notion on the main screen, also in full screen mode.

That sounds simpler. But again, I must point out that changing window sizes requires the use of Move or Resize Window, which is not very fast, and which is subject to a macOS bug that MIGHT cause the KM macro to fail to work properly. Also, I probably need to know whether you mean "maximized" or "full screen". These are different things. (The difference is whether or not the window controls are visible.)

I don't know what that means. If you are using another piece of software, it might conflict with a KM macro. Or it might help a KM macro work faster. I just don't know.

How quick do you need this macro to operate? As I said, Move and Resize Window is not a very fast action, due to macOS problems which KM is compensating for.

Once again, your IF statements seem to be redundant. I don't think I need to write a macro with any IF statement. All I have to do is swap the positions/screens of those two apps.

Since I don't own either app, what I will probably do is use substitute apps in my macro and you will have to make the change manually. That should be easy.

Since I don't have access to a second monitor right now, I may not be able to test my app properly. You may have to test it to see if it works.

I'll start writing the macro now. I'm not sure how quickly it will be ready, but perhaps 30 minutes.

Okay, I think I got it working. But I have only one monitor, so I really don't know if my macro will work on a multi-monitor Mac where the apps are full screen. It might work, or it might not. I just cannot test it. I'm sure I could make it work if I owned two displays, but I don't. There are other people on this site who have two displays and could "patch" this macro to make it work for you on a 2-display Mac. Or maybe you can patch it, if it needs any patching. You will probably have to re-enable the actions at the end of the macro. I'll upload the macro here in a few seconds...

Here it is. In my macro I'm using the apps "Apps TV" and "Apple Music" because I don't own your apps. You will have to change those names to the names of your own apps. Make sure you spot and change each occurrence, as there are several occurrences of each, not to mention the name of the variables which are storing their locations.

Once again, I'm unable to test if it works on multiple monitors. If it doesn't work, tell me what the symptoms are, and I might be able to fix it, or we may need some assistance from someone on this site who has multiple monitors and can fix it for us.

.Swap Two apps Macro (v11.0.4)

.Swap Two apps.kmmacros (13 KB)

Yes this should work! I’ll let you know once I get to my office where the dual screen monitor is setup.

Just to share, rectangle pro is a separate app that moves windows via keyboard shortcuts. It’s much faster than KM’s move windows. so I’ll probably change the “move front window to position” to a keystroke that moves the windows.

You are probably right in not using IF THEN ELSE. I haven’t had much time tinkering with TRY and GET, so I’m not very familiar with how they work. But looking at it, it seems a working solution.

I’ll update you here once I get it working. Thanks again!

Ok, it sounds like you are well-prepared to take the helm at this point.

Hello again, it’s working perfectly. Thank you so much!

It may be faster to move and resize because of KM's coping mechanisms for when a window would be positioned "off-screen" in some part, but KM's move-only should be instant.

I can't test this since I'm not going to log out and back in just to enable separate Spaces, but you should be able to un-fullscreen both apps, swap the windows, re-fullscreen them. This macro plays on KM's "Zoom" action being a toggle, so you should start with both apps' front window in fullscreen mode -- and change every mention of TextEdit to Discord and of Terminal to Notion, of course.

Swap Fullscreen Windows.kmmacros (16.4 KB)

Image

It looks more complicated than it is because, unlike @Airy's, it doesn't activate the apps to get/set window positions. That should mean less flickering and no change to which is the frontmost app.

If it works then the next step would be to state-check the windows before the first two "Zoom" actions, for if either or both windows aren't full screen.

I may have been a little lucky. But I see you got some more advice from Nige. Do consider his advice.