• 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 17:22:12 -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,

Nicely done!

And as is typical of your code very economical.  :)

I'm quite astonished and delighted by your method of extracting the first tab from the nested lists object.

I hope someone still using Snow Leopard is able to test it for compatibility.

I'm not certain I've ever tried getting the window using contains target-tab, but I've been through too many permutations now and again over the last 12+ years to remember.  In any case — well done.

Setting visible off/on doesn't properly raise a window newly set to index 1 on my system.  (Just updated to macOS 10.12.5)

I still had to resort to System Events.  (I sure wish Apple would fix that...)

--
Take Care,
Chris

------------------------------------------------------------------------------

set urlOfInterest to "https://support.apple.com"

tell application "Safari"
    try

        

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

        

        set winOfInterest to first item of (windows whose tabs contains tabOfInterest)

        

        tell winOfInterest
            set current tab to tabOfInterest

            

            if index is not 1 then
                if visible = false then set visible to true -- *maybe* speeds things up a trifle if *not* visible.
                set index to 1
                raiseWindowOne() of me
            end if

            

        end tell

        

    on error
        if window 1 exists then
            tell window 1
                make new tab at end with properties {URL:urlOfInterest}
                set current tab to last tab
            end tell
        else
            make new document with properties {URL:urlOfInterest}
            set bounds of front window to {228, 23, 1542, 1196}
        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: Safari - Bring a tab containing a given URL to the front
  • Next by Date: Re: Safari - Bring a tab containing a given URL to the front
  • 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