How to learn apple script properly Recently I am trying to set up an AppleScript to do some simple task. But I can't really find some resources that can provide me with a systematic introduction or tutorial for me to get started with Apple Script. So I'd like to hear some advices on how should I get started. Or in other words which are the recommended materials or documentations that I should follow?

I tried to go through the Apple's official documentation, but that seems too heavy to be a quick start guide.

Something like this as we have in python would be the best.

And I just attach the actual problem that I am trying to solve below.

a simple logic:

if safari is not the front most application:
    bring safari to frontmost
    if certain webpage is opened in safari:
        bring that tab of the webpage to the frontmost
    else
        open that webpage
    end if
else
    hide safari
end if


Quite simple and naive isn't it.
Hey after some exploration, I figured out the code.

And I'd like to share it with you just in case someone else might have the same need.

This code basically toggles a pre-set webpage in safari. The detailed logic can be found in the pseudo code in the question description. And I believe it can be really useful if your are involving with web-wrapped applications a lot.

set appName to "Safari"
set pageName to "&lt;+Your Page Name+&gt;"
set pageUrl to "&lt;+Your page URL+&gt;"

tell application "System Events"
    if not (exists process appName) then
        tell application appName to activate
    else if frontmost of process appName then
        # only hide application if the current tab is what we want
        # my search_tabs(pageName, pageUrl)
        set visible of process appName to (my search_tabs(pageName, pageUrl))
    else
        # still unable to give focus to desired window
        set frontmost of process appName to true
        my search_tabs(pageName, pageUrl)
    end if
end tell

on search_tabs(pageName, pageUrl)
    set tab_found to false
    set be_visible to false
    tell application "Safari"
        tell window 1
            if name of current tab starts with pageName then
                # if the current tab is already what we want then
                # return false
                return false
            end if
        end tell
        repeat with w in windows
            if name of w is not "" then --in case of zombie windows
                repeat with t in tabs of w
                    if name of t starts with pageName then
                        set tab_found to true
                        tell w to set current tab to t
                        if index of w is not 1 then
                            tell w to set index to 1
                        end if
                    end if
                end repeat
            end if
        end repeat
        # if the webpage doesn't exist
        if tab_found is false then
            tell window 1
                set current tab to (make new tab with properties {URL:pageUrl})
            end tell
        end if
        return true
    end tell
end search_tabs