Scripting Vienna

I know it’s not exactly the usual fare here, but today I’m throwing some super-geeky stuff your way. Those that don’t care about RSS readers, AppleScript or my crappy programming skills should probably just skip this entry.

For quite a while now, NetNewsWire Lite, the free version of the popular NetNewsWire, has been my RSS reader of choice. Actually, aside from a semi-disastrous and relatively brief fling with BottomFeeder at the very beginning of my RSS consumption, NNW has really been the only RSS reader I’ve tried.

Anyway, I’ve been thinking recently of upgrading to the full version (and paying the currently-discounted price of $19.99), but, for one reason or another (probably cheapness), decided to check out Vienna, an open-source alternative, and test-drive it against the 2.1 beta of the full version of NNW. As it turns out, the two are, from the standpoint of my usage pattern, practically identical. And Vienna actually suits my aesthetic sense better than NNW. The big feature they both have over NNW Lite is a Webkit-derived tabbed browser living inside the app (so you don’t have to open articles in your browser), which is handy. NNW has synching with NewsGator, which I thought might be useful, since I do a lot of browsing on my Nokia 770, but I hate the NewsGator interface, so what’s the point? The other big thing NNW has going for it is that it can integrate posting to del.icio.us, either directly or through Cocoalicious, Postr, Pukka or your browser…which brings me to the point of this post.

Now, as I’ve discussed before, I do post links to del.icio.us, but do so by way of Spurl, which isn’t supported by NNW. So the del.icio.us support doesn’t really help, unless I want to give up on Spurl, which I don’t. But such are minor impediments to the procrastinating powers of a person facing a gigantically important oral exam in less than two weeks. So I decided to try my hand at an AppleScript solution. Caveat: Despite almost 7 years of Mac ownership, I’ve never really done anything with AppleScript, mostly because I seem to have some sort of weird, highly-specific Ludditism towards scripting (and, obviously, because I’m not such a power user that it’s really necessary). So these scripts are probably pretty poorly-written. At first I was scripting NNW, but, as time went by, it became more and more apparent that, in this regard, NNW would really be no better than Vienna and, in fact, the two were virtually identical for my usage, so I then ended up writing more or less the same script for Vienna. And since that worked out so well, and since I’d gotten into the scripting mood by this point, I ended up writing a script to facilitate the Vienna-to-ecto blogging process as well.

Anyway, operating on the perhaps naïve assumption that someone might find them useful, I’m reproducing these three scripts below the jump, along with a short description of each. And if you have any suggestions for improvements, let me know.

First, the NetNewsWire-to-Spurl script. I spent way too long trying to figure out how to get NNW to open the Spurl post page in its own browser rather than pushing the link to Firefox, but, after much trial and much error, it seems that NNW’s browser chokes on some of the JavaScript on Spurl. So this just grabs the title and link of the selected article (if you’re viewing the article list) or open tab (otherwise), and sticks them in a Spurl entry form in your browser (just as if you’d hit the “Spurl!” bookmarklet in the browser).

(By the way, you are, of course, free to use, modify, improve upon or laugh derisively at any of these. If you do, I’d love to hear about it, but you’re under no obligation to acknowledge or even notify me. And yes, I know I should document these things a bit more carefully. But they’re short and simple enough that it hardly seemed necessary.)

    (* Based on del.icio.us scripts by Rob Jorgensen, 
    Mike Harris and Hedderik van Rijn.  Modification by 
    Clay Shonkwiler (http://www.sellingwaves.com)

    Feel free to modify in any way you please*)

    tell application "NetNewsWire"
        if index of selected tab is 0 then
            set delu to (URL of selectedHeadline)
            set delt to (title of selectedHeadline)
        else
            set idx to ((index of selected tab) + 1)
            set delu to (item idx of (get URLs of tabs))
            set delt to (item idx of (get titles of tabs))
        end if
    end tell
    set spurlu to "http://www.spurl.net/spurl.php?v=3&title=" & delt & "&url=" & delu
    tell application "System Events"
        activate
        open location spurlu
    end tell

Next, the Vienna-to-Spurl script. Sadly, I couldn’t figure out how to grab web pages open in tabs, only the selected article in the main list. On the plus side, Vienna supports grabbing selected text with AppleScript (which NNW doesn’t), so I can not only send title and URL to the Spurl form, but also send any selected text to the “Snip” box (as with NNW, I couldn’t figure out how to open the Spurl entry form in the Vienna browser, mostly because the GetURL tag doesn’t seem to do what it claims; if anybody knows how to do this, let me know).

    (* Syntax borrowed from 'Mail Current Article'. 
    Modification by Clay Shonkwiler

    Feel free to modify in any way you please *)

    tell application "Vienna"
        set theVersion to version
        if theVersion is greater than or equal to "2.0.0.2007" then
            set theArticle to the current article
            if theArticle is not false then
                set theTitle to the title of theArticle
                set theURL to the link of theArticle
                set theDesc to the current selection
            end if
        else
            display dialog "This script requires Vienna 2.0.0.2007 or newer"
        end if
    end tell
    set spurlu to "http://www.spurl.net/spurl.php?v=3&title=" & theTitle & "&url=" & theURL & "&blocked=" & theDesc
    tell application "System Events"
        activate
        open location spurlu
    end tell

Finally, the Vienna-to-ecto script. For those that don’t know, ecto is a desktop blogging client for both OS X and Windows that I’ve been using for a couple of years now. I use Markdown syntax for all of my blogging, so the below script grabs the title, URL and selection (if any) of an article in the Vienna article list along and starts a new post in ecto with the selection as a blockquote and title and URL appropriately linked in correct Markdown format. Between this and my hacked-up version of the CopyAllURLs extension for Firefox, I hardly even have to write links in my posts by hand anymore (if you’re interested in using CopyAllURLs for Markdown, substituting this .jar file for the included one should get the “Copy as ReST” option to output Markdown syntax instead, although I haven’t updated to the latest version, so use with caution).

    (* Based on 'Blog current article to MarsEdit' by 
    Daryl Manning & Graeme West, as well as 'ecto2 
    quoting Safari' by Adriaan Tisjelling. Modification 
    by Clay Shonkwiler (http://www.sellingwaves.com) 

    Feel free to modify in any way you please*)

    tell application "Vienna"
        set theVersion to version
        if theVersion is greater than or equal to "2.0.0.2007" then
            set theArticle to the current article
            if theArticle is not false then
                set theTitle to the title of theArticle
                set theQuote to the current selection
                set theLink to the link of theArticle
                set theSource to the containing folder of theArticle

                if the rss folder of theSource is true then
                    set theHomeURL to the home page of theSource
                    set theName to the name of theSource
                end if

                tell application "ecto"
                    activate
                    set ecto_window_count to count of document
                    if (ecto_window_count < 1) then
                        set ecto_window to make new document at the beginning of documents
                    else
                        set ecto_window to document 1
                    end if
                    tell ecto_window
                        set entry title of ecto_window to theTitle
                        set entry body of ecto_window to "From [" & theName & "][1]:" & return & "> " & theQuote & return & return & "[1]: " & theLink & " \"" & theTitle & "\""

                    end tell

                    set the focus to document 1

                end tell
            end if
        else
            display dialog "This script requires Vienna 2.0.0.2007 or later"
        end if
    end tell

Leave a Reply

If your comment doesn't appear right away, it was probably eaten by our spam-killing bot. If your comment was not, in fact, spam (and if you're actually reading this, it probably wasn't), please send me an email and I'll try to extricate your comment from our electronic spam purgatory.