Reload all open tabs in Safari 3 via AppleScript

Jun 26, '07 07:30:00AM

Contributed by: Anonymous

With the release of the Safari 3 beta, Apple has finally decided to upgrade the AppleScript-ability of the program. The biggest change I can see is the ability to directly manipulate tabs.

As an example of this functionality, I wrote a script that will reload all open tabs at a predetermined interval. Obviously, this script will only run on Safari 3.

[robg adds: In case the source linked above ever vanishes, here's the code as it existed when this story was posted:

(*
Written by:   Sean Long
On:      06/11/2007
From:     http://www.hailstonesoftware.com
Purpose:  Auto reload tabs in Safari. Currently will reload every 2 minutes.    
License:  free to use how you choose.
*)

global seconds_to_delay
set seconds_to_delay to 120

tell application "Safari"
  repeat
    repeat with i from 1 to the count of windows
      set this_win to (window i)
      repeat with j from 1 to the count of every «class bTab» in this_win
        do JavaScript "window.location.reload()" in («class bTab» j of window i)
      end repeat
    end repeat
    delay seconds_to_delay
  end repeat
end tell

This worked as described when I tested it.]

Comments (0)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070625005558732