If This Then Nuthin!

Like everyone and his mother, I use FeedBurner to put out an RSS feed from this site and others I manage. The benefits of this are vast.1

One thing about FeedBurner which is a blessing and a curse is the 30 minute wait time before the feed is updated and content is passed to anyone who’s subscribed. It’s a blessing, in that I can’t count the number of times that I’ve posted something by accident, or without properly checking, and have had to go in and draftify it quick-and-sneaky-like. But sometimes you just want to get something out there, and you’re sick of waiting.2 This is where the ability to ping a feed and manually update it comes in handy.

Sure, just go to this page and insert your actual RSS URL3 into the handy little text field and click “ping”. Before you can say “pong”, your FeedBurner feed has your brand new content. Not only that, now you can copy the URL from the address bar and bookmark that, and whenever you visit it your feed will get pinged again.

Personally, I use IFTTT to push out new posts via RSS to Facebook, Twitter, Tumblr, and whatever else is the flavor of the month. SquareSpace allows you to do this without any hassle when posting on the site, but if you want to post via email or even the mobile app, then you’re scuppered. Also, I didn’t like the way the posts looked, sometimes. So I use IFTTT instead.

If you’re posting via mobile then logging into IFTTT and manually refreshing each of the recipes (I think they’re set to check every 15 minutes by default) is a bit of a slog. So I thought I’d try my hand at writing a script that I could have run on my iMac4 at more regularly scheduled intervals, say 1 - 2 minutes. (I already use Lingon to run other scheduled scripts, so I can easily pop it into this.)

To make things easier I also included the FeedBurner ping URL in the script.

I started in Python but realized early on that AppleScript would work just as well if not better (and is easier to invoke with Quicksilver) so I moved over to that. It all went swimmingly up to a point. I wrote a script that opened each of the URLs in new Safari tabs, the FeedBurner one and whatever IFTTT recipes I wanted to list by ID at the top. The script waited a respectable amount of time for these things to load, and then closed all the tabs.

It wasn’t the prettiest solution, but it was fast to make, and it seemed foolproof. The only issue was that the user had to be already logged into IFTTT in Safari - but this wasn’t an issue at all for me. All well and good.

Until I tested it.

I’d assumed all along that simply visiting the URLs that the “Check now” link on each recipe page pointed to would have the same effect as clicking the link itself on the page. Far from it… this didn’t work at all. I then tried loading the recipe page first, then loading the “Check now” URL in the same tab, but (shockingly, I know) this didn’t work either. I turned to JavaScript, to see if I could click the link in the page with a little line of that, but there didn’t seem to be a good way to identify the link I was trying to click. I dabbed at a few feeble attempts to hack something together (click at certain coords, or click the 3rd thing with class “btn_label” on the page) and then gave up in disgust.

Here’s the script, as proof of my wasted time. If you can figure out what should happen here then let me know.

<code>-- Broken IFTTT manual refresh script<p></p><p>-- This is where you can define what recipes you want to refresh, by their IDs<br>set recipe_ids to {1563254, 1563247, 1688153}<br>set feed_url to ("myfeedurl.com")</p><p>set recipe_nos to (count recipe_ids)<br>set recipe_select to {1}</p><p>-- feedburner URL<br>tell application "Safari"<br>        open location feed_url<br>end tell</p><p>-- Loops round and for each ID loads the page in a new tab    <br>repeat with x from 1 to recipe_nos<br>    set recipe_url to "http://ifttt.com/myrecipes/personal/" & (item recipe_select of recipe_ids)</p><p>    tell application "Safari"<br>        open location recipe_url<br>    -- Wait a couple just to make sure it loads first   <br>        delay 2<br>    -- Fail miserably to click the link to refresh  <br>        do JavaScript "var links = document.getElementsByClassName('btn_label').click();"<br>    end tell<br>    set recipe_select to recipe_select + 1<br>end repeat</p><p>-- Make sure everybody is OK and we're all smiling<br>delay 10</p></code><p><code>-- Close all those new tabs<br>repeat with x from 1 to recipe_nos<br>    tell application "Safari" to do JavaScript "window.close()" in front document<br>end repeat<br></code></p>

It might be worth saying that if you have a lot of tabs to open at once and you want to bind this to a key or something, you could use a similar script, like this:

<code>tell application "Safari"<br>        tell window 1 <br>            set current tab to (make new tab with properties {URL:"http://someurl.com"})<br>            set current tab to (make new tab with properties {URL:"http://someotherurl.com"})<br>            set current tab to (make new tab with properties {URL:"http://sidoneill.com"})<br>        end tell<br>end tell<br></code>

  1. Ability to change the actual RSS location, vastly superior stats, much more accessible feed, &c

  2. For example, when you’re testing a site and how posts show up in an RSS reader.

  3. Not the FeedBurner one, but the one put out by your site.

  4. Which is always on, always connected to the internet.