Work In Progress: Store and Recall Window Position

I've been using Stay for a few years, but for some reason it occasionally forgets stored window positions. I decided just now that I might roll my own. In its current form, this pair of macros will recall the front window of any application to its stored position.


Window Position - Store.kmmacros (36 KB)

Macro screenshot

Triggering this adds (or replaces) a global variable line, like so:

Global Variable screenshot

CleanShot 2023-01-12 at 13.43.07@2x


Window Position - Recall.kmmacros (37 KB)

Macro screenshot

This macro uses any line containing the front application name to recall the front window size and position. If no matching line is found, you will be notified accordingly.


What next?

  • I'd like this to work for multiple windows of a given application, if they exist. More hassle than it's worth as this would mostly be apps with multiple documents open, each with a distinct title.
  • I'd like each window to be recalled to its particular stored position, rather than simply whichever is front-most. As above.
  • I'd like this to work for any number of screen configurations. For example, if no external monitors are attached, Position A will be recalled; if one screen is attached, Position B; two screens, Position C, etc. DONE (See below)
  • I'd like window positions to be recalled automatically when any application (whose window positions have been stored) launches, without setting individual application triggers. DONE! (See below)

If anyone would like to have a play around with the above macros or scrap them and start again, please do!

2 Likes

Hey Neil,

I think all of your requirements are possible.

token:Window Tokens [Keyboard Maestro Wiki]

%WindowName%All%

All windows in the front app.

This is quite a task you've set yourself – go slow and build it one block at a time.

-Chris

3 Likes

It's not difficult if each has a unique, and constant, title. But you've a problem if that isn't guaranteed since (AFAIK) you can only directly reference windows by title in KM.

1 Like

It was a bit of a daft idea now that I think about it. :joy:

I think a more useful function would probably be to recall the front window of each visible app to its stored position in one go. Probably not useful enough to justify the time spent figuring it out though!

The basic version is actually working great so far. I've added an Any Application trigger to the Recall macro so that apps launch in their stored positions, and I've also tried to account for different numbers of screens. It doesn't take resolution into consideration; just how many screens are available, which is good enough for me. So, when I plug my Macbook Pro into my external monitor, it recalls the position properly. As you can see there's an entry for 1 screen and one for 2.

Global Variable screenshot

CleanShot 2023-01-12 at 18.48.16@2x

I haven't tested enough to be certain, but I think it might be working!

Window Position - Store.kmmacros (37 KB)

Macro screenshot

Window Position - Recall.kmmacros (38 KB)

Macro screenshot

"Thanks for the script @noisneil ! It's exactly what I needed."

1 Like