Wednesday, April 20, 2011

Open a Collection of Tabs in Safari using AppleScript

AppleScriptImage via Wikipedia

AppleScript to open a collection of Safari tabs


Source: hints.macworld.com

Apr 18, '11 07:30:01AM • Contributed by: Dana Nau
Here's a simple AppleScript that replaces the current Safari window with a collection of tabs, each open to a different URL. I've seen several scripts that attempt to do something similar, but this one improves on them in a couple of ways:
  • It closes all of the old tabs, rather than just adding new ones.
  • It opens the new tabs directly in AppleScript, which is much faster than using system events.
The URLs in the script are just an example; obviously you'll want to replace them with others.
tell application "Safari"
  activate
  -- close all but one tab of the front window
  try
    repeat
      close tab 2 of window 1
    end repeat
  end try
  -- open the URLs in separate tabs
  tell window 1
    set URL of tab 1 to "http://weather.yahoo.com/forecast/USMD0100.html"
    make new tab with properties {URL:"http://www.weather.com/weather/today/College+Park+MD+20740"}
    make new tab with properties {URL:"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=20742"}
    make new tab with properties {URL:"http://www.accuweather.com/us/md/college-park/20742/city-weather-forecast.asp"}
    make new tab with properties {URL:"http://weather.weatherbug.com/MD/College%20Park-weather.html?zcode=z6286&zip=20742"}
  end tell
end tell
Enhanced by Zemanta

No comments: