• 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: Axel Luttgens <email@hidden>
  • Date: Sun, 21 May 2017 16:43:49 +0200
  • Ironport-phdr: 9a23:8TB8CBDDpnNMeKeZMt+CUyQJP3N1i/DPJgcQr6AfoPdwSPX5oMbcNUDSrc9gkEXOFd2CrakV1ayL7OigATVGusfe9ihaMdRlbFwst4Y/p08aPIa9E0r1LfrnPWQRPf9pcxtbxUy9KlVfA83kZlff8TWY5D8WHQjjZ0IufrymUoHdgN6q2O+s5pbdfxtHhCanYbN1MR66sRjdutMYjIZmK6s90BvEr3lVcOhS2W9kOEifkhj468qy5pJv7zhct/c8/MNcTKv2eLg1QrNfADk6KW4549HluwfeRgWV/HscVWsWkhtMAwfb6RzxQ4n8vCjnuOdjwSeWJcL5Q6w6VjSk9KdrVQTniDwbOD4j8WHYkdJ/gaRGqx+8vRN/worUYIaINPpie67WYN0XSXZdUstXSidMBJ63YYkSAOobJetXs4byqUYOoxS8CwesHuzhxDxGhnHo2qM3yPghERjD3AA8H9ICrHbZodPoP6kSS+C1y6zIwC3fYvJZxzj97JXDfBY8ofGQQbJwftTeyU80FwjYiVifs4PkMC2R1ugXt2ib8vZgVf6gi2E5rQFxuSOixtwviojJgIIa1EzE+T9iz4krPNC1TlNwb9CjEJtVrS6aNo12T9s4TGFwoCY6zqMJtYSncygNzZQqwQPUZf+fc4WQ/x7vSOKcLS1liH9rZL6znQu+/VWvx+HmS8W4zUhGoyxYmdfWrH8NzQbc6s2fR/t4+UeuxCiA2hjI6uFBPUA0ja3bK4M9wrIolpocr0DDHijulUXxka+Wal4k+umw6+TjZbXmu4WQOJF7iw7kN6Qugsi/DvoiPgcSWGib/Pyw1Lzl/ULnXLVHluA6nrXdvZzAOMgWqLK1DxVI3oo+5BuzFSqq3MkGkXUfKVJKYhOHj4znO1HUJ/D4CO+yjE6jkTh1w/DKJLnhAojRLnjfn7fuY7B961VHxQooztBe55RUBa8dIP7pQUD+qsTUDgUlPAys3+bnFNJ925sEVmKXGq+ZNL3dsUSU6eI1IumMfJMVtC/gK/g++fHul2Q5lEQZfamoxpsXdGu4Eu58LEWBeXrshskOHX0WsQo5Sey5wGGFBDdIej7mVrok4jwgA5inFZuGW5ugmqep2CagAoYQb3heDl3KGnDtIda+Vu8IeR6Vd8Z6j3RQXKC5T4I63guvrBO/1qFqNPH8/iwDqYml3cBt4+CVnhY3o29aFcOYhkidQmU8un4UWzA72rs39UVtx1PF1bVkn/NVE8d7/PBYVAomc5TRmb8pQ+vuUx7MK4/aAG2tRc+rVGk8

> Le 21 mai 2017 à 01:18, Christopher Stone a écrit :
>
> Hey Folks,
>
> I just posted with the subject “Getting Tab Index and Window ID in Safari”.
>
> This script uses that technique to find a tab (or tabs) containing the given URL and brings the first hit to the front.


Hello Chris,

Playing around above task, I first encountered following behavior that makes me vaguely reminiscent of something. I’m currently unable to fully explain it, but here is it anyway (this is with Safari 10.1.1 (11603.2.5) on OS X 10.11.6 (15G1510)).

It goes about the way a reference such as "tabs of windows whose URL begins with" gets evaluated depending on the context:

	set urlOfInterest to "https://www.apple.com";

	tell application "Safari"

		(* This yields a list of (possibly empty) per-window lists of tabs *)
		set tabsOfInterest to tabs of windows whose URL begins with urlOfInterest

		(* This seems to yield a (possibly empty) list of tabs *)
		set tabsOfInterest to {}
		repeat with someTab in (tabs of windows whose URL begins with urlOfInterest)
			set end of tabsOfInterest to contents of someTab
		end repeat
		tabsOfInterest

	end tell

For example:

	{{tab 1 of window id 2399, tab 3 of window id 2399}, {}, {tab 1 of window id 2394}}
	{tab 1 of window id 2399, tab 3 of window id 2399, tab 1 of window id 2394}


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:

	set urlOfInterest to "https://www.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
					set visible to false
					set index to 1
					set visible to true
				end if
			end tell

		end try
	end tell

But I’m probably playing with fire…

Axel

 _______________________________________________
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

  • Follow-Ups:
    • Re: 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: Christopher Stone <email@hidden>
References: 
 >Safari - Bring a tab containing a given URL to the front (From: Christopher Stone <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: 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