Routine to push a window to the screen edge...
Routine to push a window to the screen edge...
- Subject: Routine to push a window to the screen edge...
- From: David Crowe <email@hidden>
- Date: Tue, 8 Apr 2003 10:46:52 -0600
I use the following script to calculate the new position of a window
that I want pushed to a screen edge. Note that it doesn't actually
change the bounds of a window, that is left to you ... but the
parameter WindowBounds is compatible with references such as "bounds
of window 1" in applications that support this concept.
This works with multiple screens. When pushing a window 'right' for
example, the window will first go to the right of the first screen
and then, when tried again, it will go to the right of the second
screen (assuming it is to the right of the first).
"Enjoy" as they say at restaurants that want to be posh, but ain't.
(*
* bounds WindowToScreenEdge(WindowBounds,Direction) - Move window to
edge of this screen
* (in specified direction) or next screen if already at the edge
*
* WindowBounds - coordinates of a window
* Direction - 1=Left, 2=Up, 3=Right, 4=Down (matches position of
coordinates in bounds)
*
* Returns: modified coordinates
*)
on WindowToScreenEdge(WindowBounds, Direction)
if Direction < 3 then
set Sign to -1 -- Reverse everything to go left/up
else
set Sign to 1
end if
set OtherDirection to ((Direction + 1) mod 4) + 1
set ScreenMost to 0 -- Most we can go in this direction on any screen
repeat with aScreen in (screen list)
set ScreenBounds to bounds of aScreen
if (item Direction of ScreenBounds) * Sign >
ScreenMost * Sign then
set ScreenMost to (item Direction of ScreenBounds)
end if
if (item 1 of WindowBounds item 1 of ScreenBounds and ,
item 2 of WindowBounds item 2 of ScreenBounds and ,
item 3 of WindowBounds > item 3 of ScreenBounds and ,
item 4 of WindowBounds > item 4 of ScreenBounds and ,
(item Direction of WindowBounds) * Sign <
(item Direction of ScreenBounds) * Sign) then
set (item OtherDirection of WindowBounds) to
(item OtherDirection of WindowBounds) + ((item Direction of
ScreenBounds) - (item Direction of WindowBounds))
set item Direction of WindowBounds to (item
Direction of ScreenBounds)
return (WindowBounds)
end if
end repeat
set item OtherDirection of WindowBounds to (item
OtherDirection of WindowBounds) + (ScreenMost - (item Direction of
WindowBounds))
set item Direction of WindowBounds to ScreenMost
return (WindowBounds)
end WindowToScreenEdge
- David Crowe
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.