Open new Safari window with an AppleScript application

Dec 10, '03 09:05:00AM

Contributed by: pdm

The Safari dock icon behavior has always annoyed me. If you have no windows open and click on it, it will open a new Safari window. Great. However, if you have other windows open or minimized to the dock, it will just restore the last window you had open, which I find annoying. My solution: AppleScript.

You can use the System Events feature of OS X to activate any menu options. For this to work, you must have "Enable access for assistive devices" enabled on the Universal Access system preference pane.

Create a new AppleScript program in Script Editor with the following code, and save it as an application:

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
Now, find some spiffy icon to assign to your new application and drag it to the dock. I put this application right above the real Safari application, and assigned it a different icon. When you click on this new program, it will open a new Safari window. One quirk is if Safari isn't already running, it will launch two windows since Safari loads one on startup. I've only tested this on 10.3.

Comments (10)


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