Is it possible to restart an application using AppleScript?

I want to restart Safari and reopen it with some tabs that I specify.


An alternative method is to use Safari's built-in "Reopen All Windows from Last Session" feature:

tell application "Safari"
    quit
end tell

delay 2 -- Wait for Safari to close

tell application "Safari" to activate
tell application "System Events"
    tell process "Safari"
        click menu item "Reopen All Windows From Last Session" of menu "History" of menu bar 1
    end tell
end tell

To save windows/tabs from a session and be able to reopen them, there's a solution here: http://hints.macworld.com/article.php?story=20030913153245341 Be sure to read the comments, apparently there have been several updates to the scripts. Edit: Just use Chealion's answer, much smoother.

If you just want to open a certain set of tabs, you can use this script:

tell application "Safari"
    set urllist to {"http://google.com", "http://stackoverflow.com", "http://apple.stackexchange.com"}

    repeat with i from 1 to number of items in urllist
        set URL of document 1 to item i of urllist
        if i is less than number of items in urllist then
            my new_tab()
        end if
    end repeat
end tell

on 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 new_tab

Just list the addresses of the pages you want to open between the {} on line 2. Each address within "" and separated by ,.