Do something for every open application

Suggestions for how to perform actions for every open application? For instance, suppose I want to unminimize all windows of all running applications, or move them all to my main screen.

(For single windows I use a Moom keystroke to shift a window to my main screen. I know how I would calculate coordinates to do this in KM, but it would be quite elaborate – any suggestions for an easy way?)

This is very hard to do reliability because all apps do NOT support the same scripting commands for manipulating windows.

Having said that you can take a look at a script I just posted which minimizes all windows except the frontmost for the current, frontmost app. Maybe you can adapt that for your needs.

I think maybe I gave the wrong impression by my original examples. I’m asking for a general way to do “something” – something I know how to do – in every open application. I know how to perform variations on this theme in AppleScript, but it seemed that there should be a KM-native way to do it.

AppleScript solutions are also invited, because I might learn something from them.

With respect to what is an “open application”, let’s say it’s the list you get with the Force Quit dialog – i.e., does not include background processes, System Preference panes, etc.

There are somethings KM to do that would apply genericly to all apps, but generally you have to target an app first.

Here are two AppleScripts and a JXA that use the System Events app to target the current frontmost app. You can easily put these in a KM macro using the "Execute AppleScript" action.

Between the two of these, you should have a good starting point to create whatever other actions you want to apply to apps in general.