• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Safari - Bring a tab containing a given URL to the front
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Safari - Bring a tab containing a given URL to the front


  • Subject: Re: Safari - Bring a tab containing a given URL to the front
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 21 May 2017 19:56:31 -0500

On 05/21/2017, at 09:43, Axel Luttgens <email@hidden> wrote:
So, assuming that this behavior is not just an artefact valid for only some precise OS/AS/Safari combination, one could quickly get the reference of a tab containing the wanted URL, then the reference of the window containing that tab, all of this without having to resort to tab indexes or window ids:


Hey Axel,

Unfortunately it doesn't look like this method can be made to work with Google Chrome.

You can get to the first tab whose url is the one you're looking for.

But you can't get to the window using that tab as a reference — not with a bare whose clause anyway.

Okay, I figured out how to do it with the Tab-ID.

Google uses a tab-ID to reference a tab, but it requires a tab-index when setting the current tab, so making the right tab active requires a more brute-force approach.

--
Take Care,
Chris

------------------------------------------------------------------------------
# Auth: Christopher Stone { Building on work of Axel Luttgens }
# dCre: 2017/05/21 19:14
# dMod: 2017/05/21 19:48 
# Appl: Google Chrome
# Task: Bring a tab containing a given URL to the front.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Google_Chrome, @Bring, @Window, @Tab, @Containing, @URL, @Frontmost
------------------------------------------------------------------------------

set searchStr to "https://www.macupdate.com/"

tell application "Google Chrome"

    

    try

        

        repeat with tabOfInterest in (tabs of windows whose URL contains searchStr)
            set tabOfInterest to contents of tabOfInterest
            exit repeat
        end repeat

        

        set tabID to id of tabOfInterest

        

        set theWin to item 1 of (windows where id of tabs contains tabID)

        

        tell theWin
            set index to 1
            raiseWindowOne() of me
            set tabIDList to id of tabs

            

            repeat with i from 1 to length of tabIDList
                if item i of tabIDList = tabID then
                    set active tab index to i
                end if
            end repeat

            

        end tell

        

    on error

        

        if window 1 exists then
            tell window 1
                make new tab at end with properties {URL:searchStr}
            end tell
        else
            make new window
            tell active tab of front window to set its URL to searchStr
        end if

        

    end try

    

end tell

------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on raiseWindowOne()
    tell application "System Events"
        tell (first application process whose frontmost is true)
            tell window 1 to perform action "AXRaise"
        end tell
    end tell
end raiseWindowOne
------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Safari - Bring a tab containing a given URL to the front (From: Christopher Stone <email@hidden>)
 >Re: Safari - Bring a tab containing a given URL to the front (From: Axel Luttgens <email@hidden>)

  • Prev by Date: Re: Getting Tab Index and Window ID in Safari
  • Next by Date: Re: Getting Tab Index and Window ID in Safari
  • Previous by thread: Re: Safari - Bring a tab containing a given URL to the front
  • Next by thread: Re: Safari - Bring a tab containing a given URL to the front
  • Index(es):
    • Date
    • Thread