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:
- Checks if Safari is already running and creates new window (without switching spaces)
- 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