
Ever since Gruber linked to the new Mac OS X Automation site, I’ve been a bit obsessed with finding ways to automate workflows and tedious tasks I do on my Mac. With Snow Leopard’s newly enhanced services functionality, it’s much easier to do than ever before.
One thing I’ve long wanted to automate was the creation of clean Amazon affiliate URLs. A while back Amazon offered affiliate users the ability to create links from within Amazon itself using a bar along the top of the site, but the URLs it produces are far from clean. For example, this is the link Amazon provides for it’s Kindle through the Associates Link To This Page script.
http://www.amazon.com/gp/product/B00154JDAI?ie=UTF8&tag=carpeaqua-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=B00154JDAI"
There is a lot of cruft in the URL that I don’t want to paste into MarsEdit, an email or wherever else I’m linking to a product page. What’s puzzling is that to get to the page, you really only need to append "/dp/", the product ID and your tracking ID for it to be a valid URL.
http://www.amazon.com/dp/B00154JDAI/ref=nosim/carpeaqua-20
I’ve usually worked around this by copying the Amazon created URL to my clipboard, pasting it into BBEdit, cleaning it up and then expanding my associate ID using TextExpander. With Services, I can automate this down to a single step.
I created a Safari service that allows me to select the product ID from any Amazon page URL and create an affiliate link from it. The clean, affiliated URL is then copied to my clipboard so I can paste it in whatever application I desire.
Here’s what to do:
- Open Automator and create a new Service.
- Set the service to receive selected text in Safari
- Drag the “Run AppleScript” automator action into your workflow
- Copy the script below in. Be sure to replace the
"ref=nosim/carpeaqua-20"line with your own referral ID.
on run {input, parameters}
set the_url to "http://www.amazon.com/dp/" & input & "/ref=nosim/carpeaqua-20"
set the clipboard to the_url
return the_url
end run
- Save your service.
To test the service out, head to any Amazon URL and select the product ID (the string after /dp/). Right-click on the text and run your newly created service. A short, clean and affiliated Amazon URL is now on your clipboard.
The workflow on this isn’t perfect given that you can’t just copy in the entire URL, but given AppleScript’s lack of regular expression functionality, this was the best route I could think of taking.
If you find this service useful you could make me rich by either buying yourself a Kindle using this link or (even better) buy me one.
