Applescript to stack the windows in the frontmost application

I would like to write, ot at least try to write, an Applescript to stack the windows in the frontmost application.TIA

Hi Bigben,

Not all applications are equally scriptable and, I might add, they are not all scriptable in the same way. I am relatively new to applescripting ('been at it for just about one year) but if you can tell me which application(s) you are attempting to script and what version of OS you are using, I’ll try to help you out. Also, this thread may be of some help:


Variable as the shade

Thinking about using this mainly with Excel and Safari. I was hoping to use the same script for more than just these 2 apps. Thanks

Getting the name of the frontmost app is actually harder than it should be. The code is not too difficult:

tell application "System Events"
set theApp to the name of some process whose frontmost is true
end tell

(or you could use:

repeat with i from 1 to count of processes
if frontmost of process i is true then
set theApp to the name of process i
exit repeat
end if
end repeat


The problem is, how to run the script. If you save it as an app and run it, it will return its own name, if yousave it as a script and run it from Script Editor it will, of course, always return Script Editor. Stupidly, if you use the System-wide script menu to run it, it will always return “System Events” as the frontmost app, this must be the “app” responsible for running things from the script menu. I can’t figure out a way around this.