I’m pulling my hair out trying to get a simple instruction to work. I’d like to set a Finder Window to be fully zoomed:
tell application "Finder"
tell Finder window 1 to set zoomed to true
end tell
But this is generating the following error for me: “Applescript Error: Finder got an error: Can’t continue .”
Can anyone else confirm this error on Mac OS X 10.4.9 ?
I am going nuts trying to figure out what’s wrong. Curiously, the following does NOT generate an error:
tell application "Finder"
tell Finder window 1 to set zoomed to false
end tell
And it does what it should. It “unzooms” the frontmost finder window if it’s fully zoomed.
I’m running Mac OS X 10.4.9. So is this a bug in the current Finder?! If so, anyone know of a workaround?
Model: iMac G5
AppleScript: 1.10.7
Browser: Firefox 2.0.0.3
Operating System: Mac OS X (10.4)
I see this has been reported as a bug in the Finder.
Here’s my first attempt at a workaround (uses GUI scripting) to effectively set the zoomed property (by clicking the zoomed button when necessary) of the frontmost Finder window.
my setZoomed(true)
on setZoomed(b)
tell application "Finder" to tell Finder window 1 to set {x, s} to {name, zoomed}
if b and not s then
tell application "System Events" to tell process "Finder" to tell window x
repeat with i in every button
if description of i = "zoom button" then tell i to click
end repeat
end tell
else if not b and s then
tell application "Finder" to tell Finder window 1 to set zoomed to false
end if
end setZoomed
It would be nice if Apple would fix this bug, but apparently they’ve left it broken for some time now.
But here’s a workaround for anyone who runs into the same problem.
Model: iMac G5 (10.4.9)
AppleScript: 1.10.7
Browser: Firefox 1.5.0.11
Operating System: Mac OS X (10.4)
Thanks, but I need a handler that sets the zoomed state (rather than just toggling it). Also, I didn’t want to assume that button 2 was always the zoomed button, seems like something that could change but maybe it’s not important to be so careful when writing a kludgy fix to a Finder scripting bug (if setting the zoomed property can break, then who can predict what will break next…)
setZoomed(true)
on setZoomed(n)
try
tell application "Finder" to tell Finder window 1 to set {c, zoomed} to {zoomed, n}
on error number e
if e = -10000 and n and not c then tell application "System Events"
if UI elements enabled then tell button 2 of window 1 of process "Finder" to click
end tell
end try
end setZoomed
This is about as compact as I think it can get. And it also has the benefit of not erroring out if no Finder windows are open, or if GUI scripting is not enabled.
hmm.
There seems to be another bug.
On my PB12(10.4.9) , If I zoom to full screen on a Finder window and then zoom back to the smaller window all is fine.
But if I zoom full screen (–> {0, 44, 1024, 764}) and then close the window. Then open a new window the window opens at the Zoomed size ( full screen ). So so good this is expected.
But if I then try to zoom down to the smaller window, it zooms out past the bounds of the screen.(–> {0, 44, 1138, 1166})
This will persist for any new window for the that folder.
The only way I can get the window back is to use a bounds script or change the rez of the screen back and forth.
I’m afraid there are a number of bugs relating to windows in Finder. The inconsistency of this one can be particularly frustrating.
Incidentally, a window’s primary buttons can usually be identified by description without resorting to a repeat loop.
For example:
on set_zoomed(z)
tell application "Finder" to tell Finder window 1 to if exists then
if zoomed then
if not z then set zoomed to z
else if z then
tell application "System Events" to tell (first button of process "Finder"'s window 1 whose description is "zoom button")
if exists then click
end tell
end if
end if
end set_zoomed
set_zoomed(true)