Send the front most window to back? bring the back to front?

Continuing the discussion from Toggle Between Window 1 and Window 2 in any Application:

Is there a way to get one like this which would send the front window to back? or bring the backmost window to front? (without resetting the window order, as CMD ` will do.


Hey Allen,

I haven't seen a utility on the Mac that could do that since OneClick (long ago).

This is no problem.

Generic-Test 01.kmmacros (2.0 KB)

Also see this macro for ideas on what can be done.



This is super-fantastic!

Can’t help but wonder… is the oppose pretty simple to wrangle? Count the current app’s windows, send the front most window behind all those?

Ah, it looks like send window to... isn’t an option.

Even still, bringing the backmost window forward is more than 1/2 the battle.

Bring every non-front window to the front?

(Added:) Also, Many Tricks’ Witch work great. Use it all day long, even when I’m not confined to a laptop screen.

Big fan of Witch, but it doesn’t have shortcut for “back-most window”

Visually, moving all windows in front of the current would not be a pleasant experience. I have an idea that API for that just don’t exist…

Hey Allen,

I asked Peter to implement this feature a long time ago, and he told me he didn’t see a good way at the time.

I suspect this is still the case, but you can file a feature request and find out.

Peter Lewis <>


1 Like

I was thinking about it last night, and my assumption is that Apple doesn’t make “send to back” available, as a security measure.

Yes, but ugly is often preferable to undone.

Yes, there is no “sent this window to the back” API. You can only bring a window to the front.

So you could, if you really needed to, do something like:

  • For Each Index in 2 … WINDOWCOUNT()
    • Bring Window Index to the Front

You could try it and see how bad it is visually. It might be fund to watch…

Haha, no, I’ve seen it in other apps, or if one clicks on Google Chrome’s dock icon.

I’m perfectly fine with "bring last open window to the front. It’s allowed me to, sanely, go though the 50+ open windows in and boil it down to just 4 which addressing.

A big thank you to @ccstone for the script and @peternlewis for Keyboard Maestro. And to my friend Donny for reminding me that KM does a lot of work with window placement, etc.


PS backstory… Apple Mail will no longer reliably close windows when they are moved from the inbox into All Mail… so the vast majority of the open windows I had were from messages that were already read & replied to.

Hey Allen,

Run this AppleScript from Script and see if it doesn’t make your housekeeping a little easier.

If you like it you can run from a Keyboard Maestro Execute an AppleScript action.


# Close Message Windows using a Pick-List.
tell application "System Events"
  if quit delay ≠ 0 then set quit delay to 0
  tell application process "Mail"
    set winList to windows
    set messageWinNameList to {}
    repeat with i in winList
      if not (exists of button "Get Mail" of toolbar 1 of i) then
        # set end of messageWinList to contents of i
        set end of messageWinNameList to name of i
      end if
    end repeat
  end tell
end tell
tell application "Mail"
  set closeWinList to choose from list messageWinNameList with title "MESSAGE WINDOWS" with prompt ¬
    "Choose which windows to close:" default items {item 1 of messageWinNameList} ¬
    with multiple selections allowed
    repeat with i in closeWinList
      close window i
    end repeat
  end try
end tell

Thanks @ccstone - I’m perfectly happy with the solution of just bringing the back-most window forward.

by the time I have only 5 messages open, the built in Control-Tab feature of Keyboard Maestro is all that’s needed. Now that I can cycle from back to front, I doubt my too-many-windows issue will get as bad again.

I have struggled with restocking windows for many years, in QuicKeys, KM, AppleScript, and who knows what else. Here's what I believe:

  • A window's index can be set to 1

  • The window whose index is 1 is the front window (AppleScript's "front window")

  • Although no error occurs, nothing happens when you try to set a window's index to other than 1.

  • You may not get the results you expect: do you know what index your application returns for minimized windows as opposed to the front (or back) visible window?

  • Are you sure that an application that uses window tabs is not treating each one as a window (in addition to it's being a tab of another window)? (I think I have encountered this, but it does sound implausible.)

  • Screwing around with window indices is bad news anyway, because windows exist that are not normal visible application windows (palettes, etc.) that are not visible but ready to be made visible, depending on how applications implement that. (This may be an outdated belief, but if you ask for an application's WINDOWCOUNT(), you may very well be surprised by what you get.) Bind the following to a keystroke and try it in different applications under different circumstances:

    Though you would think you could at least move a window to the back.

Hey Mitchell,

Keyboard Maestro only manages standard windows.

See this macro for a more comprehensive view:

From what Peter’s told me OSX does not support negative window indexing, so there’s no way to send a window to the back except to re-stack all of them.

I’m not aware of a utility that could do this since OneClick on Mac OS 9.x.


Good to know.

Which belief is outdated?

On further thought an experimentation, I can see why setting the index of a window might not make sense (You would think that Apple would make index a read-only property; currently, if you try to set the index of a window you don’t get an error, but nothing happens.) Suppose you have 4 finder windows. The obvious AppleScript :

 set the index of the first window to the index of the last window

wouldn’t make sense — what happens to the index of the last window when this is executed? You’d end up with two windows with index 4 and no index with index 1.

(On the other hand why does setting the index of a window to 1 work — what happens to the index of the front window when you do that? Apple must have put special code in for that case.)

Simply put, the only operation on windows is “bring a window to the front”.

Your example would work fine. If you start with windows 1,2,3,4, you’d end up with windows 2,3,4,1 (ie 2 becomes the front window). There is no confusion about what happens. But Apple does not support this.

So the index is read/write, but the only allowable write is “1”.


Peter, just to be clear to neophytes like me, as soon as the window becomes frontmost, it is Window #1.

So, maybe a better example would be:

  • Start with windows in this order: A, B, C, D
  • Set window “B” to frontmost, or to index 1, and the order becomes:
    B, C, D, A