Safari New Window

Safari New Window icon

Download: Safari New Window

Previously I have written AppleScripts to open new windows for TextMate, Sublime Text 2 and also Safari. But the latter was somehow corrupt when using with Mac OS X 10.8.3, so I rewrote it based on previous two, adding features in the process:

  1. Checks if Safari is already running and creates new window (without switching spaces)
  2. Activates Safari if it’s not running yet.

The full source code is here:

-- quickly check if app is running.
-- Thanks https://discussions.apple.com/message/13184433#13184433
on appIsRunning(appName)
    tell application "System Events" to (name of processes) contains appName
end appIsRunning

property appName : "Safari"

-- Open new windows or If app is not already running, start it
if appIsRunning(appName) then
    tell application appName
        make new document
        activate
    end tell
else
    tell application appName to activate
end if

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s