Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Open Safari to multiple tabbed pages Web Browsers
I wrote this script to allow the opening of multiple pages in tabs as the startup homepage. It may not be pretty, but it works.
tell application "Safari"
  activate
  set the URL of document 1 to "http://www.XXXXXXX.com"
  my new_tab()
  set the URL of document 1 to "http://www.XXXXXX.com"
end tell
on new_tab()
  tell application "Safari" to activate
  tell application "System Events"
    tell process "Safari"
      «event prcsclic» «class menI» "New Tab" of «class menE» "File" of «class mbar» 1
    end tell
  end tell
end new_tab
Replace the X's with whatever sites you want and keep repeating the code (my new_tab() and set the URL... lines) for each page you'd like to have open. I am sure that there is a much better way to do it, but I have no clue what I am doing and it only took me five minutes to write. The "new_tab" code was "borrowed" from Apples "Combine Windows" script. Sorry if it offends anybody and please don't sue me.Mine opens up 10 pages and works great.

Also this requires that you have installed the UI Scripting Beta. Finally, you need to be sure that the "Enable access for assistive devices" option is checked in the Universal Access System Pref Panel.

[robg adds: The script works as expected (quite cool, actually!), though I haven't used it as an app yet (just ran it from ScriptEditor).]
    •    
  • Currently 3.38 / 5
  You rated: 3 / 5 (8 votes cast)
 
[56,377 views]  

Open Safari to multiple tabbed pages | 15 comments | Create New Account
Click here to return to the 'Open Safari to multiple tabbed pages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open Safari to multiple tabbed pages
Authored by: jpkang on Apr 16, '03 10:33:23AM

This is simpler: if you have a folder of bookmarks (I have one
called "News" that contains eight sites) on your Bookmarks
Bar, you can open them all at once in tabs in the current
window by selecting "Open in Tabs" at the bottom of the list.
No scripting necessary!



[ # ]
Open Safari to multiple tabbed pages
Authored by: robg on Apr 16, '03 01:31:41PM

Right, but the script will open Safari with those tabs already revealed. Saves a Command-click on the shortcut bar, basically ;-). Or lets you open a set of pages that you don't have in your bookmarks bar...

-rob.



[ # ]
Open Safari to multiple tabbed pages
Authored by: lhoong on Apr 17, '03 12:01:16AM

Actually, if you already have a folder of bookmarks you CAN get
them all loaded on startup by using the following script:

tell application "Safari" to activate

tell application "System Events"

click button "Startup" of window 1 of application process
"Safari"

end tell

where "Startup" is the name of the folder in the BookMark Bar.
The above script requires installation of UI Scripting Beta.



[ # ]
Open Safari to multiple tabbed pages
Authored by: supermacfan007 on Jul 31, '03 03:00:10PM

For some reason, whenever I try to run an applescript, it always seems to come up with a dialogue box saying either

"Expected end of line, etc, but found identifier"

or

"expected expression, property or key form, etc, but found uknown token"

and then when i want to save it says

"the script file 'untitled' wouldn't compile; you won't be able to save it in compiled form, only as text"

Does anyone know why this is happening/ I have never really used applescript before, and am very much a beginner



[ # ]
Not with sub folders
Authored by: andyland on Apr 17, '03 11:40:13AM

But what if you have sub folders in a bookmark bar folder? If
you nav to the sub folder there is no "open in tabs", and
command clicking doesn't work. I can't even open one bookmark
in a new tab if it is in a sub folder.

Andy



[ # ]
Not with sub folders
Authored by: Michael.Massing on Feb 11, '05 04:34:15AM

a workaround: organize your bookmarks however you like, but duplicate the ones you want to auto-open in a folder that only exists for that purpose.

best,
M.

---
If a nation expects to be ignorant and free, in a state of civilization, it expects what never was and never will be. - Thomas Jefferson to Col. C. Yancey, 1816



[ # ]
Carefull
Authored by: pwharff on Apr 16, '03 12:26:16PM

QUOTE from above:

"http://www.XXXXXXX.com"

Be carefull. =)



[ # ]
Open Safari to multiple tabbed pages
Authored by: seekbus on Apr 16, '03 12:37:41PM

Where does Safari store the home page info at? It isn't in the
com.apple.Safari.plist file in Preferences. If you knew where the
home page info was stored, it could probably be editted there to
open multiple tabs on launch.



[ # ]
Open Safari to multiple tabbed pages
Authored by: zona on Jun 20, '03 05:26:34PM

~/Library/Preferences/com.apple.internetconfig.plist

This is where the information is accessed from.



[ # ]
Slight bug
Authored by: skatz13 on Apr 16, '03 02:09:56PM

I noticed after submitting this hint that Safari can not be open for this script. I will play around and see if I can set up an "if" and "then" in the script.



[ # ]
Open Safari to multiple tabbed pages
Authored by: mr. applescript on Apr 16, '03 10:34:22PM
Good work! Here's a version using a repeat loop iterating a list of URLs:
set the URL_list to {"http://www.apple.com/applescript/
", 
"http://www.apple.com/macosx/", "http://www.apple.com/
itunes/", "http://www.apple.com/iphoto/", "http://
www.apple.com/safari/"}

tell application "Safari"
	activate
	repeat with i from 1 to number of items in URL_list
		set this_URL to item i of URL_list
		my new_tab()
		set the URL of document 1 to this_URL
	end repeat
end tell

on new_tab()
	tell application "Safari" to activate
	tell application "System Events"
		tell process "Safari"
			click menu item "New Tab" of ¬
				menu "File" of menu bar 1
		end tell
	end tell
end new_tab


[ # ]
Integration of Tips
Authored by: Leontes on May 09, '03 03:24:51PM

I was fiddling around with applescript and came up with this way
of doing the same sort of thing:

set the URL_list to {"http://us.imdb.com/StudioBrief/", "http://
slashdot.org/", "http://apple.slashdot.org/", "http://
www.gallup.com/poll/", "http://news.com.com/", "http://
www.snopes.com/info/whatsnew.asp", "http://
www.macsurfer.com/", "http://www.macosxhints.com/", "http:/
/www.versiontracker.com/macosx/", "http://www.spymac.com/
", "http://www.memepool.com/", "http://news.google.com/"}

tell application "Finder"
repeat with i from 1 to number of items in URL_list
set this_URL to item i of URL_list
open location this_URL
end repeat
end tell

This applescript will open a list of URL's in a single window in
Safari under tabs. Very useful for checking out the sites you
read every day. To edit, drag the strip into the Script Editor. To
change the URL's just boot up applescript editor and change the
information in the quotation marks. You can add or take
away, the number doesn't matter.

To make this work:

(under internet options under system preferences) Make Safari
your default browser... (under general preferences in Safari)
Block pop up windows, select "in the current window" for open
links from applications [this will only alter the behavior of
safari]. Enable Tabbed browsing under tabs.

This is my first applescript. It's kinda fun.



[ # ]
Integration of Tips
Authored by: zarkon55 on Nov 16, '03 12:40:16PM

All of these tab tricks do not work in latest Panther 10.3.1

Try this instead:

tell application "Safari"
activate

my new_tab()
set the URL of document 1 to "http://news.google.com/news/en/us/technology.html"
my new_tab()
set the URL of document 1 to "http://news.com.com/"
my new_tab()
set the URL of document 1 to "http://maccentral.macworld.com/"
my new_tab()
set the URL of document 1 to "http://www.versiontracker.com/macosx/"

end tell

on new_tab()

delay 1
tell application "System Events"
tell process "Safari"
keystroke "t" using command down
end tell
end tell

end new_tab



[ # ]
Open Safari to multiple tabbed pages
Authored by: Azurite on Feb 05, '07 08:31:41PM

Is there a way to automate this so it acts every time Safari opens? I'm completely new to AppleScript, but Firefox is giving me horrid font rendering issues that won't resolve easily, so I'd like Safari to perform at least some of the basic things Firefox does.



[ # ]
Open Safari to multiple tabbed pages
Authored by: Misosaki on Aug 01, '07 02:14:46PM

Maybe try using an Automator workflow, or save a copy of the script as an application? You could keep it in the dock or call it from an app launcher and it'll open all the links every time you click on it. (Unless Safari can be set to allow multiple home pages, but so far editing the .plist hasn't worked here.)



[ # ]