NetNewsWire to Safari Reading List

Description

(Requires Safari 5.1 or later) This script adds the current article in NetNewsWire to Safari 5.1's new "Reading List". This script can be added to the scripts folder of NetNewsWire. When activated, it will take the current active article and add it to Safari's Reading List for later review.

The Code

(*
http://veritrope.com
NetNewsWire to Safari Reading List
Written by David A. Cox
Version 1.0
July 13, 2011

Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/code/netnewswire-to-safari-reading-list
*)


--Clear out some variables we need to use in different parts of the script
property currentUrl : ""
property currentTitle : ""

--Here we get the URL and name of the current article by calling another part of the script
getURLfromNNW()

--Here we create the dialog to get the text you want to note your read later link with
set ReadLaterDialog to (display dialog "Preview Text" with title ¬
        currentTitle with icon stop ¬
        default answer ¬
        currentTitle buttons {"Add to Reading List", "Cancel"} ¬
        default button 1 ¬
        giving up after 30)
       
--ToFix For some reason, the title set by this script is overwritten in Safari by the articles name a moment after it is set.
--This section uses the info gatehred to add the article to the reading list.
if button returned of ReadLaterDialog is "Add to Reading List" then
        tell application "Safari"
                add reading list item currentUrl with title text returned of ReadLaterDialog
        end tell
end if

on getURLfromNNW()
        tell application "NetNewsWire"
                set headUrl to ""
                set headName to ""
                set mainList to URLs of tabs
                set mainListIndex to index of selected tab
                set mainTitles to titles of tabs
                set webUrl to (item (mainListIndex + 1) of mainList)
                set webName to (item (mainListIndex + 1) of mainTitles)
                try
                        set headUrl to URL of selectedHeadline
                end try
                try
                        set headName to title of selectedHeadline
                end try
                -- work out if we're in a tab or a regular view
                if headUrl is equal to "" and webUrl is equal to "" then
                        display dialog "Sorry, you don't appear to have anything selected in NetNewsWire" with title app_title
                        return 1
                else if webUrl is equal to "" then
                        set currentUrl to headUrl
                        set currentTitle to headName
                else -- no headline but there is a webpage
                        set currentUrl to webUrl
                        set currentTitle to webName
                end if
                --return currentUrl
        end tell
end getURLfromNNW