Mesh link all tabs in Safari window

@ttscoff 's outstanding Applescripts 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 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


3 Likes

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

2 Likes

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.

Figured this out: Mesh link all open documents (in Preview, Word, etc.)

3 Likes