Resize Windows depending on monitor resolution

Hi, I use an external monitor when I’m home and I find annoying when using my ibook with its display to have to resize windows that go out of the display. Is there a way to recognize which monitor I’m using (if the ibook display or a 19" widescreen) to automatically resize windows to fit the screen?
Here I have found a script by Jeff Kelley’s http://blog.slaunchaman.com/2008/05/20/resize-your-windows-automatically-for-different-resolutions/ that I’m trying to modify to my needs but I get an error on conditions (variable desired_width not defined). Could you help me? IS there a more automatic way to do the same (in the script below you have to detail which window has to be resized)
Thanks, here’s the script:

tell application "Finder"
	set screen_resolution to bounds of window of desktop
	set screen_width to item 3 of screen_resolution
	set screen_height to item 4 of screen_resolution
end tell

tell application "System Events" to tell process "Dock"
	set dock_dimensions to size in list 1
	set dock_height to item 2 of dock_dimensions
end tell
set {resolution} to button returned of (display dialog "Scegli risoluzione" & return & return buttons {"iBook", "Wide"})
if resolution contains "iBook" then
	set desired_width to 1024
else
	if resolution contains "Wide" then set desired_width to 1400
end if

set side_space to screen_width - desired_width
set left_bound to (side_space / 2)
set right_bound to left_bound + desired_width
set bottom_bound to screen_height - dock_height
set top_bound to 22 (* for the menu bar *)

try
	tell application "iTunes"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

try
	tell application "Firefox"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

try
	tell application "Mail"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try


Take the curly braces off the variable in the set command.

set resolution to button returned of (display dialog "Scegli risoluzione" & return & return buttons {"iBook", "Wide"})

With them, resolution is set to either “i” or “W”. The braces cause the button name to be coerced to a list the (list of the characters of the text) and the first item is then assigned to the variable.

Thx Chris, but if I take the braces off the dialog displays only the first item and then (if I click on button) I get an error “impossible obtain button returned of {{button returned:“iBook”}, “Wide”}.”
?
Nestor

Hi,

it’s not recommended to use frequently used keywords like resolution, which is a reserved word in a few applications.
Maybe there is a terminology clash, the display dialog syntax is correct

I can not fathom how removing the braces from the target of the set command could possible affect the list of button names.

Though I did discover a suspicious circumstance just now. You stared with this code:

set {resolution} to button returned of (display dialog "Scegli risoluzione" & return & return buttons {"iBook", "Wide"})

If I take out the braces from both resolution and the button list:

set resolution to button returned of (display dialog "Scegli risoluzione" & return & return buttons "iBook", "Wide")

When I compile it, it changes to this (Script Editor changes the parens to braces!):

set resolution to button returned of {display dialog "Scegli risoluzione" & return & return buttons "iBook", "Wide"}

Which, when run, reproduces both of your symptoms (one button, and “Can’t get button returned of {{button returned:“iBook”}, “Wide”}.” error).

Try copying-and-pasting this code again:

set resolution to button returned of (display dialog "Scegli risoluzione" & return & return buttons {"iBook", "Wide"})

Otherwise, you are probably left hunting down some kind of OSAX or script context issue (script launcher overriding display dialog?).

Thanks a lot! Now it works!
Nestor