Michael Leddy Posted April 5, 2023 Share Posted April 5, 2023 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. Link to comment
Stephen_C Posted April 5, 2023 Share Posted April 5, 2023 7 minutes ago, Michael Leddy said: If anyone knows how to have a workflow recognize highlighted text without the need for Command-C, I’d love to know. Use a Universal Action trigger limited to text? Stephen Link to comment
vitor Posted April 5, 2023 Share Posted April 5, 2023 For your next workflow, Consider taking a look at the Automation Tasks first. There are several to grab information from the Safari tabs. Add to that a Replace Utility and a Copy to Clipboard Output and you’d reach your goal without requiring code, plus with a high degree of confidence that it works correctly. For an interactive tutorial on making a workflow, see the Getting Started Guide. Link to comment
Michael Leddy Posted April 5, 2023 Author Share Posted April 5, 2023 (edited) 48 minutes ago, Stephen_C said: Use a Universal Action trigger limited to text? Stephen Stephen, thanks for your suggestion. Could you explain where that would go? Vitor, thanks for your suggestions. I’ll look at the Automation Task to create Markdown links. I’m in way over my head here, but that’s often a good way to learn. I should mention that the Safari extension URL Linker doesn’t work properly in Ventura. A working extension would make all of this a lot simpler. Edited April 5, 2023 by Michael Leddy Link to comment
Stephen_C Posted April 5, 2023 Share Posted April 5, 2023 (edited) 28 minutes ago, Michael Leddy said: Could you explain where that would go? Right at the start of the workflow. Take a look at the link in my previous email and the link also on the help pages about universal actions[1]. Edit: [1] See here. Stephen Edited April 5, 2023 by Stephen_C Link to comment
Michael Leddy Posted April 5, 2023 Author Share Posted April 5, 2023 Thanks again, Stephen. I’m really lost though trying to figure it out. For now I’ll stick with the ones I have -- pretty quick to do from the keyboard. I just thought it would be nifty if a workflow could get the highlighted text without Command-C. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now