Looking for a utility for super-basic on-the-fly text processing stuff

I wind up with a bunch of random copy/paste stuff I have to clean up. One example is Amazon URLs. I seem to send them to people quite a bit, and the URLs always seem to be a bazillion characters long. The actual URL of the product is a tiny fragment of that, and I’d like to be able to have a little utility to auto-clean it somewhere in the process.

Apart from doing something weird in Keyboard Maestro, is there any software I should be looking at?

Brett Terpstra used to sell an app that cleaned up Amazon links (among other things), but it seems to have gone to the Great App Store in the Sky. So I recommend something weird in Keyboard Maestro, namely a search-and-replace with a search regular expression of

^.*/(?:dp|gp/product)/([^/?]+).*$

and a replacement of

https://www.amazon.com/gp/product/$1

Like this:

That will turn this URL,

https://www.amazon.com/gp/product/B09C311C3J?pf_rd_r=VE1BTTR0DZ597RB2DVQZ&pf_rd_p=8fe9b1d0-f378-4356-8bb8-cada7525eadd&pd_rd_r=5f57cc17-3612-4036-81c3-bef2d505be32&pd_rd_w=dLflD&pd_rd_wg=B2cyn&ref_=pd_gw_unk

into this:

https://www.amazon.com/gp/product/B09C311C3J

I’ve been using this regex for ages, and it’s always worked.

3 Likes

Shortcuts can extract url components. Might be worth waiting for monterey.

That’s interesting. I could map Cmd-Option-C or something to the “fancy copy”, and the conflict palette would let me have multiple options for cleanup.

Thanks for the regex!

If its just for Amazon links you might want to setup an affiliate link. Once established you will see a small extra toolbar with a share button on the left hand side. Select text and you will receive a short url :wink:

-https://amzn.to/3D2SmN1-

Also you can easily create a page on your website with the various products you often recommend to your clients :wink:

Most of these aren’t specific recommended products, but rather a client looking for something and me just trying to point them in the right direction. Either that or me communicating with my girlfriend about which dog vitamins we need to buy. :smiley:

I use the Bitly extension in PopClip – select the URL in the location bar in Safari. (There are other link shortener extensions for PopClip.) This is what the extension puts on the clipboard:

https://amzn.to/xxxxxxxx

(The example has been anonymized.)

Does that strip out the offending garbage at the end of the link? Or does it just shorten it for clipboard purposes?

I’d prefer to strip it all out because I prefer to not have any more Amazon tracking nonsense following me around than necessary. :slight_smile:

It’s just a URL shortener – when expanded by Amazon when the URL is clicked you’re back to the original long and indecipherable URL.

I suppose the real question is: is it possible to get an URL linking to product on Amazon that is just a direct link to that product with no other hidden info in the URL? I suspect the answer is “no”, not unless you do what @drdrang suggests.

I agree that this is a darling job for regular expressions. Either in Keyboard Maestro if you want a shortcut to process one entry at a time, or, if you want to paste in a lot of entries and batch process them, then something like BBEdit (very fast/robust editor for large text files, with a great find/replace window), RegExRX (most robust regex-specific tool for Mac that I know of), or CyberChef (free tool for all sorts of data manipulation including regex replacement).

I usually create Alfred workflows for things like this.