Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save alexzaporozhets/4ae7e859c6468ebc7e37 to your computer and use it in GitHub Desktop.

Select an option

Save alexzaporozhets/4ae7e859c6468ebc7e37 to your computer and use it in GitHub Desktop.

Revisions

  1. @vitorgalvao vitorgalvao revised this gist Jul 22, 2014. 2 changed files with 24 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions get_title_and_url.applescript
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    # Browser
    # applescript to get frontmost tab's url
    # applescript to get frontmost tab's page title
    # Keep in mind that when asking for a `return` after another, only the first one will be output.
    # This example is meant as a simple starting point, to show how to get the information in the simplest available way.

    # Google Chrome
    tell application "Google Chrome" to return URL of active tab of front window
    22 changes: 22 additions & 0 deletions get_title_and_url_from_front_browser.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # This example will return both the URL and title for the frontmost tab of the active browser, separated by a newline.
    # Keep in mind that by using `using terms from`, we’re basically requiring that referenced browser to be available on the system
    # (i.e., to use this on "Google Chrome Canary" or "Chromium", "Google Chrome" needs to be installed).
    # This is required to be able to use a variable in `tell application`. If it is undesirable, the accompanying example should be used instead.

    tell application "System Events" to set frontApp to name of first process whose frontmost is true

    if (frontApp = "Safari") or (frontApp = "Webkit") then
    using terms from application "Safari"
    tell application frontApp to set currentTabUrl to URL of front document
    tell application frontApp to set currentTabTitle to name of front document
    end using terms from
    else if (frontApp = "Google Chrome") or (frontApp = "Google Chrome Canary") or (frontApp = "Chromium") then
    using terms from application "Google Chrome"
    tell application frontApp to set currentTabUrl to URL of active tab of front window
    tell application frontApp to set currentTabTitle to title of active tab of front window
    end using terms from
    else
    return "You need a supported browser as your frontmost app"
    end if

    return currentTabUrl & "\n" & currentTabTitle
  2. @vitorgalvao vitorgalvao revised this gist Sep 24, 2013. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions get_title_and_url.applescript
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,4 @@ tell application "Safari" to return URL of front document
    tell application "Safari" to return name of front document
    # Webkit
    tell application "Webkit" to return URL of front document
    tell application "Webkit" to return name of front document
    # Opera
    tell application "Opera" to return URL of front document
    tell application "Opera" to return name of front document
    tell application "Webkit" to return name of front document
  3. @vitorgalvao vitorgalvao revised this gist Jul 4, 2013. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions get_title_and_url.applescript
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,4 @@ tell application "Webkit" to return URL of front document
    tell application "Webkit" to return name of front document
    # Opera
    tell application "Opera" to return URL of front document
    tell application "Opera" to return name of front document
    # Camino
    tell application "Camino" to return URL of current tab of front browser window
    tell application "Camino" to return name of current tab of front browser window
    tell application "Opera" to return name of front document
  4. @vitorgalvao vitorgalvao revised this gist May 10, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions get_title_and_url.applescript
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,9 @@ tell application "Google Chrome" to return title of active tab of front window
    # Google Chrome Canary
    tell application "Google Chrome Canary" to return URL of active tab of front window
    tell application "Google Chrome Canary" to return title of active tab of front window
    # Chromium
    tell application "Chromium" to return URL of active tab of front window
    tell application "Chromium" to return title of active tab of front window
    # Safari
    tell application "Safari" to return URL of front document
    tell application "Safari" to return name of front document
  5. @vitorgalvao vitorgalvao created this gist Apr 15, 2013.
    22 changes: 22 additions & 0 deletions get_title_and_url.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # Browser
    # applescript to get frontmost tab's url
    # applescript to get frontmost tab's page title

    # Google Chrome
    tell application "Google Chrome" to return URL of active tab of front window
    tell application "Google Chrome" to return title of active tab of front window
    # Google Chrome Canary
    tell application "Google Chrome Canary" to return URL of active tab of front window
    tell application "Google Chrome Canary" to return title of active tab of front window
    # Safari
    tell application "Safari" to return URL of front document
    tell application "Safari" to return name of front document
    # Webkit
    tell application "Webkit" to return URL of front document
    tell application "Webkit" to return name of front document
    # Opera
    tell application "Opera" to return URL of front document
    tell application "Opera" to return name of front document
    # Camino
    tell application "Camino" to return URL of current tab of front browser window
    tell application "Camino" to return name of current tab of front browser window