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

No, if you start with windows A, B, C, D and you set window B to be frontmost you would end up with windows B, A, C, D

Essentially the behaviour is the same as you get when you click on a non-front window - that window comes to the front, the previous front window is now second, and so on.

OK, thanks for clarifying.

In your example, you moved the first window to the end:

My point, and my example was that the mythical semantics of the non-functional AppleScript:

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

has perfectly well defined behavioural semantics (A,B,C,D ➤ B,C,D,A) but does not in fact work, which I described, but which does not in fact work because the only valid set index is 1:

set the index of the third window to 1

Which also has perfectly well defined behaviour (A,B,C,D ➤ C,A,B,D) and the advantage that it does actually work.

I think it is confusing to provide such detail for things that don’t work.

####So, let me see if I now have it straight about what CAN be done:

  • The only change in the stack of windows that can be made, is to make a selected window as frontmost.
  • You could do this by telling AppleScript to set the index of a window to 1
  • When you move a window to the front, all of the other windows remain in the order that they were.

####However, with a simple AppleScript, we CAN move the first window to the back


tell application "TextWrangler"
	set winList to every window
	set indexList to index of every window
	set nameList to name of every window
	log nameList
	log indexList
	--- It appears that the GET of every window always gets in
	--- the current stack order
	--    Set each window index to 1 in reverse order
	--    except for current window 1
	repeat with oWin in (items 1 through -2 of reverse of winList)
		log (name of oWin)
		set index of oWin to 1
	end repeat
end tell
1 Like

Isn’t that the part where the user has to watch the windows dance around? Made me kinda seasick to watch.

Nope. It is very smooth, with very little perceived motion.

Here's an animated GIF of the process happening, as "A Window" is moved to the back:

On rereading this page I had a thought about moving windows to positions other than 1: the restriction is the same as for applications — you can make an application frontmost, but you can’t rearrange the order of applications (that you would get by ⌘→. The concept both windows and applications are dealing with is simply whether or not they are frontmost — “index 1” for windows, “frontmost true” for applications.

I do wish that Apple provided a way to send a window, and even an application, to the back. In my experience I rarely gave any thought to arbitrary reordering, but I have often wanted to send a window to the back.

My recent experiments have shown the Bring to Front — whether with KM’s action or through AppleScript — is a no-op if the window is not in the current space/desktop.

Hey Mitchell,

Apple in their infinite wisdom has provided no public API for working with Spaces.

The fact that application windows can disappear into a Space is astonishing ineptitude…


Another experiment shows that bringing a window to the front by setting its index to 1 doesn’t give the window focus. The above GIF shows that. Note that the window made front seems to have focus briefly then loses it. Does anyone know how to give the front window the focus? I suppose I can just click on it, but I was hoping for something cleaner.

I am reviving a seven year old thread here because I am interested in experimenting with something like this.

In the above example, @JMichaelTX used TextWrangler windows and the OP was about Apple Mail windows.

Is there any solution available that works for a mix of multiple applications on the same screen?

Update: More recent discussion here: Send Currently Active Window to Back