Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: A New Service to Shorten URLs System 10.6
Snow Leopard only hintI submitted a hint a while ago, regarding a way to create short URLs using Perl, AppleScript and Automator, which also required that one download a package of software.

Since that hint was published, the URL service (qgf.in) went down because the owner left it to the wolves. So here's a new Service that completely eliminates the need for Perl and the download. This service uses bit.ly, but you can choose another website (make sure you get the API format [usually http://short.url/api?url=http://website.com/]) as well.

First, create a new Service in Automator. Set the top bar to read 'Service receives selected URLs in any application', and check 'Replaces selected text.'

Then drag in a Run AppleScript action from Utilities. Copy/paste the following script into the script field:
on run {input, parameters}
  set dlstring to ((path to temporary items folder as string) & "shortURL.html")
  tell application "URL Access Scripting"
    download ("http://bit.ly/api?url=" & (item 1 of the input)) to dlstring replacing yes
  end tell
  set x to open for access dlstring
  set aurl to read x
  close access x
  return aurl
end run
Save the service as Shorten URL. Now you can right-click on any URL and shorten it, which is useful for sites like Twitter.

The main difference between this service and the previous shortener is that the new one uses temporary files, and no Perl/UNIX, while the previous used a separate Perl/UNIX script to do its job.

[crarko adds: I tested this, and it works as described.]
    •    
  • Currently 2.80 / 5
  You rated: 1 / 5 (5 votes cast)
 
[12,731 views]  

10.6: A New Service to Shorten URLs | 18 comments | Create New Account
Click here to return to the '10.6: A New Service to Shorten URLs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: A New Service to Shorten URLs
Authored by: renaultssoftware on Dec 30, '10 07:32:47AM

Dang, I just realized I could use cURL. Someone might want to write a hint…

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: mozart111 on Dec 30, '10 09:00:11AM

Doesn't work for me. Error -1700

"Can't make item 1 of {} into type Unicode text (-1700)



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: renaultssoftware on Dec 30, '10 10:57:58AM

You're sure you selected the URL?

Dang… I should've added "Receives <selected text> in <any application>" in the hint body. Can you add that Craig?

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: renaultssoftware on Dec 30, '10 06:34:26PM

Never mind. I saw it was there already. *headdesk*

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: donbarger on Jan 01, '11 07:11:52AM

I get the same error :(



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: jfa643 on Dec 30, '10 09:11:52AM

Works as described. Thank you for the nice hint.



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: Yirgacheffe on Dec 30, '10 10:27:37AM

Thanks for that hint, works fine. :-)

I have one question: What do I have to alter in order to paste the shortened URL to the clipboard?
I tried this:
'Tell application "Finder" to set the clipboard to aurl'

instead of 'return aurl'
But I only got an error.

Anyone any idea?

Viele Grüße
:-) Dirk



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: BiL Castine on Dec 31, '10 08:12:15AM

Just drag in a "Copy to Clipboard" action after the AppleScript action. You might also want to remove the check next to "Replaces selected text" at the top of the service.



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: renaultssoftware on Dec 31, '10 09:17:24AM

Also, no need to tell Finder. This command works:

set the clipboard to shortURL

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: donbarger on Jan 01, '11 04:39:24AM

Did not work - I get "Can't Make Item 1 of {} into type Unicode text. (-1700)

Any suggestions? I would really like to use this.



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: renaultssoftware on Jan 03, '11 06:21:41AM

Have you selected the full URL? Works fine for me when I select a URL in Safari's address bar and run the service.

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: donbarger on Jan 03, '11 06:35:31AM

Unfortunately I did select the entire link. When I do this, it comes up and says "The Action Run Apple Script encountered an error."

I click Show Workflow and it opens the "Shorten URL" file under services.

I really would like to get this to work. It would be a huge time saver for me.



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: shhrr8 on Jan 01, '11 02:15:26PM

Why not use Apple's built in URL shortener? For example, in a new Mail message highlight any text and Add Link from the Edit menu or type Command-K. Same for TextEdit. Then just copy and paste the link somewhere. I do this all the time when emailing long links or to embed in my documents. Similar facility exists in Keynotes and Pages and perhaps other applications on your Mac.



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: dashard on Jan 03, '11 04:55:49AM

That's not actually a URL shortener, but rather hypertext and a hypertext link. That is, it's the full URL disguised under some link text, rather than the full URL represented by a shorter URL.



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: btorbo on Jan 04, '11 05:30:34AM

Is there a way to do the same with hyperlinks, and is it possible to assign a keyboard shortcut to the service as well?



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: hdh15 on Jan 07, '11 07:10:59AM

Tried to set up Automator. It shows up under services when I highlight a URL in Google Chrome and Safari, but does not show up in Firefox or when I highlight a URL in Mail even though the script is Service receives URL in any Application. Any reasons why?



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: everkleer80 on Jan 07, '11 08:05:45AM

Firefox does not support services - or at least it still didn't last time I checked. It's very disappointing and that's why I stopped using it a few years ago after many hours spent searching for a workaround/plugin/hack to enable services in it. Not sure why mail wouldn't work though, my guess is maybe the OS is not recognizing the text as a URL - perhaps you should try making your service just accept text. If that works then maybe you can add code to the action that will validate whether the text is a full URL.



[ Reply to This | # ]
10.6: A New Service to Shorten URLs
Authored by: slferris on Feb 22, '11 12:09:00PM

Worked for me for a short time, but no longer. Just says "The action “Run AppleScript encountered an error." I wonder if something has changed with the site "http://bit.ly/" such that it is now necessary to login. Any ideas?

Thanks



[ Reply to This | # ]