• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Swap foreground and background windows
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swap foreground and background windows


  • Subject: Re: Swap foreground and background windows
  • From: "Nigel Garvey" <email@hidden>
  • Date: Tue, 26 May 2009 20:51:59 +0100

Luther Fuller wrote on Mon, 25 May 2009 13:10:38 -0500:

>… Could I change the order of windows, specifically, could I
>move the front window to the back? Here's the script ...
>
>tell application "TextEdit"
>	activate
>	set winList to (id of every window) as list
>	set newOrder to (rest of winList) & {item 1 of winList}
>
>	repeat with i from 1 to (count items of newOrder)
>		set winID to (item i of newOrder)
>		set index of window id winID to i
>	end repeat
>end tell
>
>The first thing I noticed was that it didn't work.

When told to change a window's index, TextEdit puts the window in front
of the one that currently has the target index — which is fine when
bringing the window forward (the more usual situation), but not when
pushing it further back. In that case, it needs to go _behind_ the
current index holder. A general script for this purpose could look
something like this, which works with both TextEdit and Safari:

  to changeIndex for thisWindow under thisApp to newIndex given
refocussing:refocussing
    tell thisApp
      set windowCount to (count windows)
      if (newIndex < 0) then set newIndex to newIndex + windowCount + 1
      --> Range check here if required <--
      set oldIndex to thisWindow's index
      set thisWindow's index to newIndex
      if (oldIndex < newIndex) then set index of window newIndex to
newIndex - 1
      if (refocussing) then tell (get window 1) to set {visible, visible}
to {false, true}
    end tell
  end changeIndex

  tell application "TextEdit" -- or "Safari"
    activate
    my (changeIndex for window 1 under it to -1 with refocussing)
  end tell


NG
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Swap foreground and background windows
  • Next by Date: Re: How can I save the Terminal output?
  • Previous by thread: Re: Swap foreground and background windows
  • Next by thread: Opening AppleScript *.app files for editing
  • Index(es):
    • Date
    • Thread