brentvardy.com

Applescript to start safari with tabs

Applescript to start safari with tabs
My preferred browser on the mac is Apple’s Safari, however there is a feature on Firefox I do miss on Safari. I really like how Firefox remembers any tabs you have open with web pages you are browsing so that the next time you open up Firefox the tabs automatically reload. To try and imitate this I’ve written a small AppleScript script which if used to open Safari will do so and load some pre-defined web pages each in a new tab. I use the script with Safari version 4 but I’m sure it will also work with previous versions. Let me know if this is not the case. Here’s the script:


-- Applescript to open Safari and preload tabs with specific URLS

-- Enter the URL for Tab 1-3
set Tab1_url to "http://www.newsgator.com"
set Tab2_url to "http://www.twitter.com"
set Tab3_url to "http://www.challengelogic.net"

-- Tell Safari to ope the new Tabs as specified

tell application "Safari"
activate
set the URL of document 1 to Tab1_url
my open_tab()
set the URL of document 1 to Tab2_url
my open_tab()
set the URL of document 1 to Tab3_url
my open_tab()
end tell

-- Subroutine to open a new tab

on open_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 open_tab



As you can see this script opens 3 web pages in new tabs, hopefully you can see how easy it would be to add additional code to open up even more sites as required. There is a slight problem with the script and that is you must set Safari so that new windows open with something other than the top sites page. I’m currently fairy new to Applescript but will try and fix this in a future version when I have more time. There may also be a better way of doing this. Until they feel free to try out my script at your peril :).

View Comments|Add Comment


Read More...