window resize

You know how when you click that little green button in the menu bar of iTunes, you can switch back and forth between the small player and large player? is something like that possible with applescript? and if so, where might someone start with that?

If you want to use the little green button, you have to catch every zoom of the window using the ‘should zoom’ action, and override it with custom bounds. The following code worked for me, using a window which was by default 600x400 pixels. Make sure to get a grasp on how objects move when you resize windows, because erratic things can happen if you’ve got them set to move in the wrong manner. Use the springs in the ‘size’ pane in IB to ensure that objects move properly. This code uses the top left corner as the origin of the window. Read the comments in the code for more info.

property isZoomed : missing value --> Boolean var which stores the window state

--> The size of the window in it's default and adjusted sizes (Length,Height)
--> Add 22 to the height to account for the title bar!
property sizeUnzoomed : {600, 422} --> The window's default size
property sizeZoomed : {300, 172} --> The window's adjusted size

--> Catch the should zoom action and override it with a custom, static bounds
on should zoom theObject proposed bounds proposedBounds
	toggleWindow(theObject)
	return false --> Tell the app not to perform the default zoom operation
end should zoom

--> A subroutine which toggles the window's size
to toggleWindow(theObject)
	set {pxLeft, pxBottom, pxRight, pxTop} to bounds of theObject
	
	if isZoomed then
		(* Set the window to it's default size *)
		set {offsetX, offsetY} to sizeUnzoomed
		set isZoomed to false
	else
		(* Set the window to it's adjusted size *)
		set {offsetX, offsetY} to sizeZoomed
		set isZoomed to true
	end if
	
	set bounds of theObject to {pxLeft, (pxTop - offsetY), (pxLeft + offsetX), pxTop}
end toggleWindow

j

thanks Jobu for your reply, this will give me a great base to start on.

thanks again…