# Mesh link all tabs in Safari window

**URL:** https://discourse.hookproductivity.com/t/mesh-link-all-tabs-in-safari-window/4843
**Category:** Share Hookmark automation
**Created:** [March 18, 2022, 8:42pm UTC](https://discourse.hookproductivity.com/t/mesh-link-all-tabs-in-safari-window/4843 "2022-03-18T20:42:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![capcrime](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@capcrime](https://discourse.hookproductivity.com/u/capcrime)
#### Post date: [March 18, 2022, 8:42pm UTC](https://discourse.hookproductivity.com/t/mesh-link-all-tabs-in-safari-window/4843/1 "2022-03-18T20:42:02Z")

</div>

@ttscoff 's outstanding [Applescripts](https://github.com/ttscoff/hook_goodies/tree/e7a10cdba78a639409369899a94a9d0392a7efac) for mesh linking Finder items and hooking Finder items to a clipboard URL got me experimenting with ways to mesh link all tabs in a Safari window. I adapted Brett’s script for mesh linking Finder items to do this. Below is the Applescript which gathers all tabs in a Safari window and mesh links them in one fell swoop, and here is a [link to download a Keyboard Maestro macro](https://www.dropbox.com/s/51y41jeev2x7mn0/HOOK%20TAB%20LINKS.kmmacros?dl=0) implementing the script (uploaded in disabled state).

(Sorry, I can’t get the first three and last lines of the script into the code text box).

* * *

use AppleScript version “2.4” – Yosemite (10.10) or later  
use scripting additions  
tell application “Safari”

```
set _URLs to {}
set _topWindow to window 1
set _tabURLs to every tab of _topWindow
repeat with _item in _tabURLs
	set end of _URLs to URL of _item
end repeat
set _targets to _URLs
if (count of _URLs) > 1 then
	repeat with _URL in _URLs
		repeat with _target in _targets
			if _URL is not equal to _target then
				tell application "Hook"
					set x to _URL
					set _src to make bookmark with data x
					set y to _target
					set _tgt to make bookmark with data y

					hook _src and _tgt
				end tell
			end if
		end repeat
	end repeat
else
	display dialog "There must be 2 or more tabs."
end if

```

end tell

* * *

---

<div class="post-metadata">

### Author: ![ttscoff](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/ttscoff/32/309_2.png) [@ttscoff](https://discourse.hookproductivity.com/u/ttscoff)
#### Post date: [March 19, 2022, 2:54pm UTC](https://discourse.hookproductivity.com/t/mesh-link-all-tabs-in-safari-window/4843/2 "2022-03-19T14:54:54Z")

</div>

This is really smart. Should almost be a built-in feature 🙂

---

<div class="post-metadata">

### Author: ![capcrime](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@capcrime](https://discourse.hookproductivity.com/u/capcrime)
#### Post date: [March 20, 2022, 11:13am UTC](https://discourse.hookproductivity.com/t/mesh-link-all-tabs-in-safari-window/4843/3 "2022-03-20T11:13:01Z")

</div>

Next idea: Mesh all open documents in an app, e.g., all open PDFs in Preview. I can’t seem to make that work. I can gather all POSIX paths of open PDF docs in a percent encoded list, but then I can’t make the script you developed loop through the list and make bookmarks with the paths.

---

<div class="post-metadata">

### Author: ![capcrime](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@capcrime](https://discourse.hookproductivity.com/u/capcrime)
#### Post date: [March 21, 2022, 2:23pm UTC](https://discourse.hookproductivity.com/t/mesh-link-all-tabs-in-safari-window/4843/4 "2022-03-21T14:23:13Z")

</div>

Figured this out: [Mesh link all open documents (in Preview, Word, etc.)](https://discourse.hookproductivity.com/t/mesh-link-all-open-documents-in-preview-word-etc/4865)
