Script to Create Shortened URL

As a preface, I have no experience with Applescript or any other language for that matter. However, I have a particular problem that many have, but I have yet to find a solution.

Problem: I need to automate a url shortener.

A little context will help though for the specific use case. What I am actually doing is shortening an “itemlink” from DEVONthink and transforming it into a web URL. The reason being, is that two pieces of software I use do not allow you to utilize item links as hyperlinks (Evernote and Notion.so). However, if I use TinyURL.com, I can put the itemlink in and get a recognizable web URL that Evernote and Notion will accept.

I am sure this is possible, but I don’t know how. Additionally, I thought it might be easiest in Shortcuts on iOS, but I can’t find a way to do that there either. The only iOS shortcuts I found don’t accept an item link either. Currently, I am doing this manually, but I might do this 15-100 times a day, depending on what I am doing.

Any help or direction would be greatly appreciated.

Mark

I’m not familiar with itemlinks, however perhaps this Shortcut example will give you an idea on how to solve what you are trying to do

https://www.icloud.com/shortcuts/563111882b284ba9aca4ffa3e3d0dd80

It’s not clear to me where you are retrieving the item link and how you would ideally like to pass it into Shortcuts. If the former isn’t adequate, maybe you can elaborate on your flow. — jay

Does it have to be TinyURL? Would bit.ly be acceptable?

The reason I ask is that I believe Bitly has an API that you could use…

time passes

I just checked and it appears that Bitly’s API has gotten a lot more complicated since I last used it, so I don’t have example code to recommend.

I’ve created a quick shortcut that I think does what you are after. You should be able to broadly use the same basic approach to do the same thing on macOS in the language of your choice if you need an equivalent there; it would be a good excuse for you to select and dabble in a language :nerd_face:

The Shortcut will accept URLs via the share sheet should your app share it’s app URLs in that way, otherwise, it’ll use whatever is on the clipboard which is the way most of my apps of choice share app links when I’m not manually constructing them.

It then gets the results of a URL that converts the passed URL (which somewhat unusually I found must not be URL encoded), pulls out all of the web links, then matches the preview URL, carries out a little substitution to make it not a preview link (if you examine all the links on the page of results, you might well figure out why I do this :wink:), copies the resulting link to the clipboard, and then shows it to you and offers to open it as a test.

Hopefully this matches what you were after and you can further tailor it if required, to suit your specific needs.

Edit
I figured it would be worth me highlighting that while I tested this with some app URLs, I’m not a DEVONthink user, so I haven’t explicitly tested with the URLs it uses.

2 Likes

I would have preferred Bit.ly, but TinyURL is the only one that transforms a DT item link.

Thank you. This is very helpful.