NetNewsWire To TextEdit

Description

This script is for use with NetNewsWire: It will take the current story you are reading and add it to a text file (along with an intro bit of text). It is useful for creating a list of links to share with someone. The script also makes it easy to mark a link as NSFW.

Installation and Configuration

Install this script into the scripts folder for NetNewsWire (see their documentation if you are not sure how).

You need to set the path of the file to use in order to run this script. You can enter it in this part of the AppleScript: --Set the file to use for saving your links by dragging the file between the "" marks below set Path2TextFile to ""

No other changes should be needed.

If you want to add a keybaord shortcut for this script, use the built-in OS X control panel System Preferences -> Keyboard & Mouse -> Keyboard Shortcuts. Just create a new keyboard shortcut for the Application "NetNewsWire", the Menu title as whatever you named the script, and then your desired keyboard shortcut (I use the standard Save keyboard shortcut, as NetNewsWire does not use it for anything else).

The Code

(*
http://veritrope.com
NetNewsWire To TextEdit
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-textedit
*)


--Set the file to use for saving your links by dragging the file between the "" marks below
set Path2TextFile to ""

--Lets make sure the file path is not still blanked out
if Path2TextFile is "" then
    display dialog "You need to open this script in AppleScript Editor,
and set the path for the file you would like to use to store your links"

end if

--Here we set up all our defaults and clear out variables
property documentname : ""
property currentUrl : ""
property currentTitle : ""
set NSFW to false

--Let's try to open the document in TextEdit in case it is closed
--try
tell application "TextEdit"
    open Path2TextFile
end tell

--Let's figure out what the file name is we are to write to
set oldDelimiters to AppleScript's text item delimiters -- always preserve original delimiters
set AppleScript's text item delimiters to {"/"}
set documentname to last text item of Path2TextFile
set AppleScript's text item delimiters to oldDelimiters

--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 clever opening you want to use for the link
set PostDialog to (display dialog "Clever Quip above URL " with title ¬
    currentTitle with icon stop ¬
    default answer ¬
    currentTitle buttons {"update the list!", "NSFW"} ¬
    default button 1 ¬
    giving up after 30)

--Now we build out the text based on the URL, and what your asked, and make note of if it is safe for work or not
set URLintro to text returned of PostDialog
if button returned of PostDialog is "NSFW" then
    set NSFW to true
end if
set theString to URLintro & "
"
& currentUrl

--And finally we call the section of the script that writes the text to text edit
appendMe(theString, NSFW)
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
on appendMe(theString, NSFW)
    tell application "TextEdit"
        if NSFW is true then
            set last character of document documentname to (last character of document documentname & return)
           
            --Here we mess with the font to make NSFW stuff stand out
            set savedFont to font of last character of document documentname
            set savedColor to color of last character of document documentname
            set font of last character of document documentname to "Helvetica-
Bold"

            set color of last character of document documentname to {65535, 18601, 19374}
            set last character of document documentname to (last character of document documentname & theString & " ")
            set font of last character of document documentname to savedFont
            set color of last character of document documentname to savedColor
            set last character of document documentname to (last character of document documentname & return)
        else --The case that the URL has not been marked as NSFW, we post it to the top of the list in the default font
            set first character of document documentname to (return & first character of document documentname)
            set first character of document documentname to (theString & "
                        "
& first character of document documentname)
        end if
        save document documentname
    end tell
end appendMe