A Service for adding shortened URLs to Safari's Reading List

Nov 15, '11 07:30:00AM

Contributed by: warmfuzzyapps

Recently, I was playing around with Safari's Reading List feature, and I was pleased to see that there is a Services menu item to add links to the list from other applications. Unfortunately, it didn't work for a bunch of the URLs that I tried to add.

The link detection scheme is overly strict and it seems to only work with well formed URLs that contain the scheme. This didn't help at all when trying to add links from Twitter where just about every one is shortened and does not contain the http:// cruft.

I have been wanting to learn more about Automator and Applescript so without further ado I present my lax version of the 'Add to Reading List' Service.

To setup the service:

Here's the script:
--
-- Automator Service - Add to Reading List - lax version
-- 
-- http://warmfuzzyapps.com/2011/07/add-to-reading-list-lax-version/
-- Wiley Wimberly
--
-- The default service that adds links to Safari's Reading List is a
-- bit on the strict side when deciding what constitutes a URL and it
-- doesn't work well for adding shortened URLs from apps like twitter.
-- This version is more tolerant and will prepend http:// if the  
-- selected text does not already start with http:// or https://.
--
-- Service receives selected text in any application.

on run {input, parameters}

    set theItem to item 1 of input

    if theItem starts with "http://" or theItem starts with "https://" then
        set theUrl to theItem	
    else
        set theUrl to "http://" & theItem
    end if

    tell application "Safari"
        add reading list item theUrl
    end tell

    return theUrl

end run

From this blog post. The code is also listed here.

[crarko adds: This pretty much just reformats the URL so Safari will be happy with it.]

Comments (0)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2011080115203027