Subscribe to
Posts
Comments
NSLog(); Header Image

Safari AppleScript Broken

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…

6 Responses to "Safari AppleScript Broken"

  1. 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.

    1. [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.

  2. 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).

  3. [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.

  4. I have no idea why your script used to work, but now doesn't.

    But you can just script the window position directly:

    tell application "Safari"
        set zBounds to {8, 28, 1208, 1028}
            repeat with w in every window
                set bounds of w to zBounds
            end repeat
    end tell
    1. 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. 😉


Comments RSS

Leave a Reply


Warning: Undefined variable $user_ID in /var/www/vhosts/nslog.com/httpsdocs/wp-content/themes/nslog/comments.php on line 96

Please abide by the comment policy. Valid HTML includes: <blockquote><p>, <em>, <strong>, <ul>, <ol>, and <a href>. Please use the "Quote Me" functionality to quote comments.