Jul 23, '04 11:11:00AM • Contributed by: Anonymous
Read the rest of the hint for the script...
Safari Launcher v0.05
The purpose of this code is to launch the Safari web browser, while overriding the defined Home Page. This is particularly useful due to an ongoing bug within Safari that causes it to periodically reset the user defined settings to the factory defaults. This behavior adversely effects the Home Page setting and is very irritating, hence the need to code this script. The code and logic within this sciprt has been provided "AS IS" and the responsibility for its operation is entirely your own.
tell application "Safari"
if not (exists (document 1)) then
--
-- Safari is *Not* Opened, Call Open New Window Function, Go To Preferred Page
-- and Activate Safari to Enable Scripting
--
tell application "Safari" to activate
my open_new_window()
--
-- Set Safari Location to Preferred Page
--
set the URL of document 1 to "http://localhost/"
else
--
-- Safari is Opened, Bring it To Front and Open New Tab w/Preferred Page
--
if (exists (URL of document 1)) then
my open_new_tab()
end if
--
-- and Activate Safari to Enable Scripting
--
tell application "Safari" to activate
--
-- Set Safari Location to Preferred Page
--
set the URL of document 1 to "http://localhost/"
end if
end tell
--
-- Open New Window Function
--
on open_new_window()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "New Window" of menu "File" of menu bar 1
end tell
end tell
end open_new_window
--
-- Open New Tab Function
--
on open_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 open_new_tab
I am sure many of you can find ways to do the same thing better (as mentioned, this is my first script), but this does do the trick. As you can see from the code above, simply alter the lines with "http://localhost/" to suit your own needs, save your changes and you're set. This can be run as a script or saved/run as an application (my own preference.) For easy access, I've added mine to the Dock.
[robg adds: I've never had an issue with Safari changing my homepage, so I suspect something else is at work here. Nonetheless, perhaps this script will be useful to someone.]
