"Copy Link and Selection" for browsers

I don’t understand why only some apps are compatible with Hook’s built in “Copy Link and Selection” but I decided to build the functionality myself for web browsers.

tell application "System Events" to set the clipboard to ""
tell application "System Events"
	keystroke "c" using command down
	delay 0.2
	set theQuote to the clipboard as Unicode text
end tell
tell application "System Events" to set FrontAppName to name of first process where frontmost is true
if FrontAppName is "Microsoft Edge" then
	tell application "Microsoft Edge"
		set theName to title of active tab of front window
		set theURL to URL of active tab of front window
	end tell
else if FrontAppName is "Safari" then
	tell application "Safari"
		set theURL to URL of front document
		set theName to name of front document
	end tell
end if
if theQuote is "" then
	set the clipboard to "[" & theName & "](" & theURL & ")"
	set the clipboard to ">" & theQuote & "\n[" & theName & "](" & theURL & ")"
end if
display notification with title FrontAppName subtitle "Copied to clipboard"

Tweaked from this article to match Hook’s “Copy Link and Selection” style which also means that you can call up hook and paste the hook to a document. Hopefully, the Hook devs will add this functionality soon since this script is brittle (only works for the apps in the script). Also keep up the good work Hook devs!

1 Like

It’s because our approach does not rely on the clipboard, but API’s if they are available; they aren’t always available. We also wanted to see what kind of traction we would get with this feature.

However, we have a goal of sharing a more general facility.

Thank you!

1 Like

thank you for sharing!