Safari AppleScript Broken
Posted November 2nd, 2009 @ 10:00am by Erik J. Barzeski
This is broken. It used to work. Script Editor complains about a missing value…
tell application "Safari" set myJS to "self.moveTo(8,8);self.resizeTo(1100,1000);" repeat with thisWin in every document do JavaScript myJS in thisWin end repeat end tell
Any ideas? This type of script comes in handy when a site resizes your browser window. I hate that…
Posted 02 Nov 2009 at 12:37pm #
Saft causes this. If you're not using Saft, perhaps some other plugin.
If your goal is to resize to fill the screen, Right Zoom might be a useful little app.
Posted 02 Nov 2009 at 1:06pm #
[quote comment="56011"]Saft causes this. If you're not using Saft, perhaps some other plugin.
If your goal is to resize to fill the screen…[/quote]
Not using Saft, and my goal isn't to fill the screen. It's to resize a window to a normal size after it's been resized by a web page's script.
I believe I have a pretty normal collection of plugins. This script used to work, though it's been so long since I've had a browser window resized on me that I haven't had much need for it in awhile, so I have no idea what's changed since it last worked.
Posted 02 Nov 2009 at 1:30pm #
Ah, Saft is only part of the problem.
Apparently there also seems to be an issue with Spaces, at least on my Mac: when I run the script from Terminal (in a different Space as Safari), nothing happens apart from the 'missing value'.
When I perform the script when Safari is in the active Space, it works (but still generates the message).
Another solution would be to make a bookmarklet out of the script (bookmarklets in the bookmarks bar can easily be triggered by a keyboard shortcut as well).
Posted 02 Nov 2009 at 7:39pm #
[quote comment="56016"]When I perform the script when Safari is in the active Space, it works (but still generates the message).[/quote]
I can run the script from Script Editor within the same space and it still fails with just the "missing value" error.
[quote comment="56016"]Another solution would be to make a bookmarklet out of the script (bookmarklets in the bookmarks bar can easily be triggered by a keyboard shortcut as well).[/quote]
I tried making a bookmarklet. No good. Nothing happened.
Here's the real problem: a bug.
Posted 02 Nov 2009 at 7:53pm #
I have no idea why your script used to work, but now doesn't.
But you can just script the window position directly:
Posted 03 Nov 2009 at 8:33am #
Jim, that script works, but has the unfortunate side effect of resizing every Safari window. Unfortunately that includes the downloads window and, bizarrely, the preferences window.
So, until the bug is fixed, I've added in checks for window visibility as well as the name "Downloads."
Now I just hope I can get my "Security" preferences pane to resize. It may require quitting Safari. Or scripting it to get back to a usable size. 😉