How to loop thru all open windows for an app?

My first KM project is to tame Stickies. I’m creating a macro that will arrange all visible stickies (while keeping them open). (This is different from the built-in “arrange” command, which rather annoyingly minimizes the stickies before arranging them.)

So I need a way to loop through all open windows for a particular app.

Does this capability exist in KM?

Hey Michael,

Yes, it can be done.

Stickies is not scriptable, but AppleScript can see it via UI-Scripting.

tell application "System Events"
   tell application process "Stickies"
      tell window 1
         set position to {0, 22}
         set size to {400, 300}
      end tell
   end tell
end tell

Keyboard Maestro can also see Stickies' windows:

Resize the Front Window.kmmacros (2.4 KB)

Here's the basics of how to iterate through the windows:

Keyboard Maestro 8.2d1 “Stickies ⇢ Resize Windows” Macro

Stickies ⇢ Resize Windows.kmmacros (5.7 KB)

You can change the resize fields to variables by inserting a variable name.

You'll have to manage the position of the windows as well.

There are a bunch of window management macros on the forum you can look at to get ideas on how to do all of this.

But don't bang your head against the wall for more than an hour at a time – if you get stuck ask for help.

-Chris