Jump to content

Use URL in clipboard as URL for workflow


Recommended Posts

I know you can set up a Web Search in Alfred then use {query} to append text to or insert text in the URL, but I am trying to figure out how to append pre-defined text to the current URL in the clipboard. So kind of the opposite. The URL changes each time, but not the appended text.

 

How would I most easily achieve this?  Use case is this: when you copy a link to an album or single or song in Apple Music or the iTunes Store, it gives you a link like this:

 

https://music.apple.com/us/album/18/1628207368

 

If you add "?ls=1&app=itunes" to that URL, it opens the item in the iTunes Store. This is really the only way you can open Pre-Release items in the iTunes Store, as for some reason they don't have a "Also available on the iTunes Store" link at the bottom like other pages do.

 

So I want the user to be able to copy a link to an item in Apple Music or the iTunes Store, type a keyword in Alfred, then paste the link, and hit Enter, then Alfred appends the "?ls=1&app=itunes" and goes to the URL with the appended text. I may also make a version where a link like the above can simply be highlighted, then the user presses a hotkey and Alfred appends the same text and goes to the URL. But I can figure that part out myself as I have other workflows like that, if you help me figure out how to add static text to a URL in the user's clipboard.

 

Thanks in advance for any help!  Let me know if anything is unclear.

Link to comment

I just created a new workflow and I see you can select "macOS Clipboard contents" as the Argument, so maybe I'm getting warmer.. but the field under that is "Prefix", and I'm thinking what I need is "Suffix"? i.e. add to the end instead of the beginning? Or is that what Prefix is somehow? :)

Link to comment

Thank you @vitor!

I got these working.. For some reason though, using {clipboard} with the version that acts on selected text works, and using {query} instead of {clipboard} works for the one where I manually paste the URL in the Alfred window. Not sure what I did wrong, but it works, so I'm glad. Thank you again.

 

Here are the workflows I ended up with:

 

https://www.dropbox.com/s/ns5dr3p68jmjete/Open AM URL in iTS.alfredworkflow?dl=0

https://www.dropbox.com/s/kd4z0irfatax8nl/Open selected AM URL in iTS.alfredworkflow?dl=0

Link to comment
1 minute ago, mattbovett said:

using {clipboard} with the version that acts on selected text works

 

Alfred gets the selected text by copying it. But check Alfred Preferences → Advanced → Selection Hotkeys. If the user has that set to “Restore previous clipboard item (uses more memory)”, the behaviour will change. So I still recommend you use {query}. In that case you can even forego the Argument and Variables Utility and have {query}?ls=1&app=itunes directly in the Open URL.

 

5 minutes ago, mattbovett said:

using {query} instead of {clipboard} works for the one where I manually paste the URL in the Alfred window.

 

That is also expected. Alfred is using text you’re giving. In this case you can also forego the Argument and Variables Utility. If those are the two versions you wanted, you don’t need to care for the clipboard.

 

12 minutes ago, mattbovett said:

Here are the workflows I ended up with

 

You can make them both into a single Workflow: one Keyword and one Hotkey, both connected to the same Open URL.

Link to comment

Okay thank you @vitor!  I will look at that and also look at combining into one workflow.

 

What if I wanted to do a version where I could go to Share > Copy Link (in Apple Music), then press a specified hotkey for an Alfred workflow, and it just adds ls=1&app=itunes to what is in the clipboard (which will be an Apple Music link like https://music.apple.com/us/album/18/1628207368), then just opens the URL (which would be "https://music.apple.com/us/album/18/1628207368ls=1&app=itunes")?

 

I tried:

Hotkey trigger (Hotkey = ^⌘I, Action = "Pass through to workflow", Argument = "macOS Clipboard Contents")
into
Args and Vars utility ("{query}?ls=1&app=itunes" - without quotes) ... (also tried {clipboard} instead of {query})
into
Open URL (left as default)

 

Nothing seemed to work.  I think one config opened the URL in Safari, and when I checked the location bar, it showed the URL with ?ls=1&app=itunes added, but it never prompted me to "Allow" to open in the Music app, so it never took me to the iTunes Store like the other workflows did.

 

Thanks again for any help.

Edited by mattbovett
Clarity
Link to comment
11 minutes ago, vitor said:

In that case you can even forego the Argument and Variables Utility and have {query}?ls=1&app=itunes directly in the Open URL.

 

This sounded good but when I paste {query}?ls=1&app=itunes directly in the Open URL action, it appears as red and won't let me save:

 

image.thumb.png.147d5011fc340f124715d2543363f364.png

 

What am I doing wrong there I wonder?

Link to comment

Ah, you’re right. I had confirmed it with just {query}, not the full thing. Keep the Argument and Variables Utility. You still only need one.

 

20 minutes ago, mattbovett said:

I tried

 

That worked for me. Check the debugger. If you still can’t figure it out, share the Workflow.

 

Another option is to connect the Argument and Variables Utility to a Run Script with default settings and code open -a 'Music' "${1}". That will tell macOS to open Music with whatever was passed-in. In that case you may not even need the Argument and Variables Utility to extend the URL. I don’t use Apple Music, so you’d have to confirm.

Link to comment

Thank you @vitor, you're truly awesome. I think I got it working to where it appends ?ls=1&app=itunes to the URL in the clipboard. Not sure why it was throwing an error before. Something like error -50 or 50. I toggled "Selection hotkeys" under Advanced between "Restore previous clipboard item" and "Leave selected item in clipboard" because I thought that might be it, but it seems to work with both, so I guess that wasn't it. Here's the workflow I ended up with:

 

https://www.dropbox.com/s/2rgi2s8zekpudp9/Open copied AM URL in iTS.alfredworkflow?dl=0

 

I'm wondering now if there's a way to combine that one ("Open copied AM URL in iTS") and "Open selected AM URL in iTS", and just use one hotkey, so the user doesn't have to learn two hotkeys. I could get some more people to use Alfred if it was just one hotkey to learn, probably.

 

I don't think I need to include / use the one where you invoke Alfred and manually paste the link into the Alfred window after all.

Edited by mattbovett
Link to comment
3 hours ago, mattbovett said:

I could get some more people to use Alfred if it was just one hotkey to learn, probably.

 

Consider diversifying the ways people can interact with it. Universal Actions are in particular useful. People already know their shortcut for it, and can use it from a link in Clipboard History as well.

Link to comment
49 minutes ago, vitor said:

 

Consider diversifying the ways people can interact with it. Universal Actions are in particular useful. People already know their shortcut for it, and can use it from a link in Clipboard History as well.

 

I use that for when I select a file in Finder and want to move it or copy it.

 

But, haven't the faintest idea of how to get started adding it to the above workflows.

 

I poked around for a bit but it's still clear as mud.

Link to comment

Right-click the canvas → Triggers → Universal Action.

  • Name: Open AM URL in iTS
  • Show for: URLs
  • Single Input Arguments

Connect it to the Argument and Variables Utility. With a single object, two new interaction modes opened up:

  • Copy a link. Now open the Clipboard History and press your actions shortcut (see what it is in Alfred Preferences → Universal Actions → Show Actions). Search for Open AM URL in iTS.
  • Select a URL anywhere. Press the Universal Actions shortcut (see what it is in Alfred Preferences → Universal Actions → Selection Hotkey). Search for Open AM URL in iTS.

Link to comment
19 minutes ago, vitor said:

Right-click the canvas → Triggers → Universal Action.

 

  • Name: Open AM URL in iTS
  • Show for: URLs
  • Single Input Arguments

 

Connect it to the Argument and Variables Utility. With a single object, two new interaction modes opened up:

 

  • Copy a link. Now open the Clipboard History and press your actions shortcut (see what it is in Alfred Preferences → Universal Actions → Show Actions). Search for Open AM URL in iTS.
  • Select a URL anywhere. Press the Universal Actions shortcut (see what it is in Alfred Preferences → Universal Actions → Selection Hotkey). Search for Open AM URL in iTS.

 

 

Thank you @vitor. I got it working. But, I think this is too many steps for the average user.

 

If they could click a song or album in Apple Music then use the Universal Action and select "Open AM URL in iTS", I could see them doing that.  But when you try that, it copies all the song information (artist name, album name etc), not the share link.

 

I will play with everything above, but I think at least one of the solutions above that I already have working will work really well for people.

 

Link to comment
  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...