Safari to Rich Text Link

Anyone have automation suggestions using only macOS standard apps (Automator, AppleScript) and/or TextExpander to create a rich text link from Safari? I would like to have the page name as the text and the URL as the link.

I am trying to find a solution on a managed system.

The answer depends on what “rich text” is on the system you’re using. If it’s HTML, make a TextExpander snippet that runs this AppleScript:

tell application "Safari"
	set theTitle to name of front document
	set theURL to URL of front document
end tell

get "<a href=" & quote & theURL & quote & ">" & theTitle & "</a>"

It will insert a link to the frontmost page in Safari. You should be able to change the last line if necessary to get some other form of rich text.


That did the trick. Thank you!

I hate to dig this up from so long ago… I am running the latest TextExpander and macOS 12.3.1. When I run this script as a TE snippet, I get the “<a href…” with the URL and title filled in, but not a rich link. I tried to paste the result into this reply, but when it posted, it DID come through as a rich link. But when I run this in, say the notes field of an OmniFocus document, I no longer get a rich link, which I am pretty sure I used to be able to do. (Ditto if I run it in any app that should handle rich text.)

I’m sure I am doing something wrong. Any help would be greatly appreciated. Thanks!