AppleScript application as a Safari Webpage I currently using an AppleScript application that launches a website (phpMyAdmin) in Safari. I keep it in my dock for easy access.

What I am looking for


When clicking on the ASA (AppleScript Application) it opens to the safari page
When I move to a different window and click the ASA again, it will bring the safari window to the front instead of reopening it in a new window/tab
If I quit the ASA the safari page will close
If I X out the tab where the website is, the the ASA will quit


If anyone has any idea how to do this it that would be great!
As other users have noted, the third and fourth bullet points are probably not worth holding on to, as it makes the first two difficult to implement:

use S : application "Safari"
property PHPMyAdminURL : "http://xxxxx/ppmya"


on run
    if S is not running then return openPHPMyAdmin()

    set _T to a reference to (every tab of every window of S whose ¬
        name contains "PHPMyAdmin" and ¬
        URL contains "/ppmya")

    if (count _T) &gt; 0 then return viewPHPMyAdmin(_T)

    openPHPMyAdmin()
end run


to openPHPMyAdmin()
    tell S
        if (count windows) = 0 then
            make new document with properties ¬
                {URL:PHPMyAdminURL}
        else
            make new tab at end of tabs of S's window 1 ¬
                with properties ¬
                {URL:PHPMyAdminURL}
            set current tab of S's window 1 to the result
        end if

        activate
    end tell
end openPHPMyAdmin


to viewPHPMyAdmin(T)
    set [T] to T
    set W to the first window of S whose tabs contains T

    set current tab of W to T
    activate S
    set the index of W to 1
end viewPHPMyAdmin


After some initial feedback from @user3439894, I removed the on quit handler as trying to use the script as a stay-open application prevents item 2 from being effectively implemented.