Zoom In/Out dialog & reposition according to screen boundaries?

I’m an utter noob to scripting in general, but just wondered if this is possible.

What I’d like is to create a small dialog box with 3 buttons (say Zoom In, Zoom Out and Cancel), when you press and hold either zoom button it invokes the zoom action in OS X (Command + Option -/+) and the Cancel button would return the screen to normal.

I’ve searched around and found this (edited a bit):

display dialog "Zoom..." buttons {"Zoom In", "Zoom Out", "Cancel"} default button 3
copy the result as list to {buttonpressed}

and also:

tell application "System Events"
	tell process "UniversalAccess"
		keystroke "+" using {command down, option down}
	end tell
end tell

tell application "System Events"
	tell process "UniversalAccess"
		keystroke "-" using {command down, option down}
	end tell
end tell

Now with the screen zoomed in, you only get to see a portion of it so the dialog box would need to move into view which is where the repositioning comes in. I presume an “if” clause or something similar woud be needed to constantly check that the dialog box is visible on screen.

I don’t know if it’s possible to find the boundaries of the screen when zoomed in or if a “click and hold” type action/variable can be made as zooming would otherwise mean clicking loads of times on the button, but this seems as good as any place to ask :slight_smile:

The reason I’m doing/want this is because I’d like to zoom in/out with only my Apple bluetooth mouse (old version, only 1 button and no scrollwheel) and so the only scenerio I can think of that would work is the proposed idea above. Though if anyone else has a better idea I’d like to know. I use the option of the zoomed screen following the mouse pointer, if that helps/conplicates things.

From what I’ve searched and found so far, I may need to use Quickeys.

Thanks for any info.

Model: iMac G5 1.8Ghz
Browser: Firefox 2.0.0.1
Operating System: Mac OS X (10.4)

You can’t move display dialog. However, this might work for you.

set zoomLevel to 0 -- assumes that you aren't zoomed in when you start the script

try
	repeat
		display dialog "Zoom." buttons {"Cancel", "Zoom Out", "Zoom In"} default button 3
		button returned of result
		
		if result is "Zoom In" then
			zoomKey("+")
			if zoomLevel < 32 then set zoomLevel to zoomLevel + 1
		else if result is "Zoom Out" then
			zoomKey("-")
			if zoomLevel > 0 then set zoomLevel to zoomLevel - 1
		end if
	end repeat
on error errMsg number errNum
	try
		-- user probably canceled the dialog, try to zoom back out
		repeat zoomLevel times
			zoomKey("-")
		end repeat
	end try
	
	if errNum is not -128 then error errMsg number errNum
end try


on zoomKey(someChar)
	tell application "System Events" to keystroke someChar using {command down, option down}
end zoomKey

You can always press escape (or command+period) to choose the cancel button, and you can press enter to choose the default button (“Zoom In”); If you use keyboard navigation, then you can also zoom out by pressing tab twice (to move the focus) and then pressing space (to choose that button).

That’s a shame I suppose I could just drag the box manually but would’ve been nicer for it to be automatically positioned. Edit: I just tried to zooming in, dragging the dialog box and then clicking zoom again and the box returned to it’s original position. I presume that’s the default position of dialog displays, bit of an annoyance.

How difficult would it be to create a Dashboard widget from the script? I know you can set a floating Widget on your desktop so that might stay in a fixed place after each button press. I’ll go Googling…

Yes, but you missed my original point of the script, which was to control zoom with the mouse only :slight_smile:

Also, is it not possible to have a click and hold ability (or something like that)? Purely for convenience again so as you don’t have to click so many times.

Thanks a ton for your help :slight_smile:

Actually, the more I think about the less feasible the display dialog repositioning is, particularly when you use the “move screen with pointer” option, you’d never be able to ‘reach’ the dialog’s buttons so it’d have to be in a fixed place.

Also from what I can find, Applescript and Widgets don’t seem to go well hand in hand or at least easily.

I guess I’ll make do with the supplied script. Thanks again Bruce.