I asked ChatGPT to write Alfred workflows to create an HTML link with selected text or title from the current tab in Safari. It took about six tries for AI to get them right. Granted, it’s easy to create links in Markdown or with aText or TextExpander doing the tedious stuff, but I wanted to see if a workflow could do it in HTML (especially useful, I’d say, for those of us who still blog and are making links on the fly). I used a Hotkey, so there’s nothing to show in the Alfred window.
URL+text: It’s necessary to highlight text, press Command-C, and then press the Hotkey. If anyone knows how to have a workflow recognize highlighted text without the need for Command-C, I’d love to know.
#!/bin/bash
text=$(pbpaste)
url=$(osascript -e 'tell application "Safari" to return URL of front document')
link="<a href=\"$url\">$text</a>"
echo $link | pbcopy
URL+title: All that’s needed is to press the Hotkey.
#!/bin/bash
title=$(osascript -e 'tell application "Safari" to return name of front document')
url=$(osascript -e 'tell application "Safari" to return URL of front document')
link="<a href=\"$url\">$title</a>"
echo $link | pbcopy
I’ve placed the workflows in a Dropbox folder for downloading:
URL+text: https://www.dropbox.com/s/1v1w4qfn28rt9ye/URL%2Btext.alfredworkflow?dl=0
URL+title: https://www.dropbox.com/s/thd9o8kogr6cvbl/URL%2Btitle.alfredworkflow?dl=0
I’m no coder, and I hope what I’m sharing here is appropriate and useful.