Add to Instapaper script

hello there,

as a huge fan of Instapaper using it on a daily basis and also using DT to view my RSS feeds, I prepared a piece of AppleScript to add selected feed entries
to my Instapaper account.

Before using it, please set the right account’s name in the script’s content.

Here we go:


set username to "username"

-- remove this part to turn off Growl notification
tell application "GrowlHelperApp"
	set the allNotificationsList to {"Success Notification"}
	set the enabledNotificationsList to {"Success Notification"}
	register as application ¬
		"Add to Instapaper" all notifications allNotificationsList ¬
		default notifications enabledNotificationsList ¬
		icon of application "DevonTHINK Pro"
end tell

tell application "DEVONthink Pro"
	
	set selectedItems to selection
	
	show progress indicator "Adding articles to Instapaper..." steps (count of selectedItems)
	
	repeat with selectedItem in selectedItems
		
		set itemURL to URL of selectedItem
		
		if itemURL is not "" then
			
			set itemName to name of selectedItem
			
			step progress indicator
			
			set command to "/opt/local/bin/curl --data-urlencode \"username=" & username & "\" --data-urlencode \"url=" & itemURL & "\" --data-urlencode \"auto-title=1\" http://www.instapaper.com/api/add"
			do shell script command
			
                        -- remove this code to turn off Growl notification

			tell application "GrowlHelperApp"
				notify with name "Success Notification" title "Added to Instapaper!" description itemName application name "Add to Instapaper"
			end tell
			
		end if
		
	end repeat
	
	hide progress indicator
	
end tell

Doesn’t work for me. I get the following “script error” message:

Thoughts?

please try to replace “opt/local/bin/curl” with “curl” - but it doesn’t work on my Mac this way so I can’t promise anything. If still having problems, please let me know.

curl probably is in /usr/bin, so maybe try changing it to /usr/bin/curl.

or if it’s not there, open a terminal and type
find / -name curl
which should (eventually) tell you where it is.

Or try:

% which curl
/usr/bin/curl

Indeed. If it’s not in the path and this fails, find should do the trick (unless it doesn’t exist).

I’m sorry I don’t understand any of this. And none of it works.

Thanks for the help, but this is another of those impenetrable mysteries of computers – why a script that works fine on one Mac should not work on another.

Sorry, that came out sounding grumpy. I appreciate everyone’s helpfulness, but sometimes I just find computers so baffling. Most times, in fact…

Hey, if you really want to get into some esoteric programming, I have a pretty decent (and still working) HP-67 calculator that I’m going to put up on ebay soon! :smiling_imp:

[Hint to Eric: Too bad Devon Tech doesn’t have a "trading post’ forum for us users.]

This is an easily penetrable mystery:

bartekb81’s script uses a version of curl, very likely installed as /opt/local/bin/curl with MacPorts, that’s not installed on your system. :slight_smile:

that’s quite possible :slight_smile: I also have a default curl installation which doesn’t support POSTing urlencoded data :confused:

But I guess it can be rewritten using python which comes with OS by default. I’ll give it a try till tomorrow and let you know. :slight_smile:

Actually a descendant of the hp67’s programming model is still alive in the hp-50 (or something like that, I have an hp-49g which I bought some years ago to play with and apparently it’s similar). these things are basically like supercharged hp-48g calculators; quite amazing for when they were introduced, and programmable in RPL, which is a language evolved from hp67-style programming. I don’t have much time to play with it anymore, unfortunatey.

having added a bit of extra software provided by enthusiasts (including an editor called “emacs”…), the source code (or an on-the-fly disassembled version of it) for the whole operating system is available at a keystroke. completely amazing. a battery-powered lisp machine!

unfortunately, RPL programs are completely unreadable 1 day after you write them, at least for me. at any rate, at the moment I have a program called “spacetime” on my ipod touch, which is nice for a little mathematical programming, but I guess in a few years I’ll just have mathematica on my then-current mobile phone. should be incredibly cool and enough for everything. [although come to think of it, if someone had told me, while I was fighting with my 8mhz, 640kb, no hard-disk, CGA graphics beast of a machine as a geeky pre-teenager, that I’d be able to open my macbook on a plane and continue programming in mathematica for hours, never mind the GUI and so on, I’d probably have thought that nothing could possibly top that-now I am instead irritated that my battery runs out]

bit of a rant there, sorry!

As promised, here comes a version of this script using python interpreter internally. It should work if the version above didn’t work on your mac. This one should do.

Please adjust the parameters at the beginning of the script. Also notice the very long line ‘set command to python …’ - it has no line breaks, please don’t break it.

set username to "your username"
set pwd to "password"

-- remove this part to turn off Growl notification
tell application "GrowlHelperApp"
	set the allNotificationsList to {"Success Notification"}
	set the enabledNotificationsList to {"Success Notification"}
	register as application ¬
		"Add to Instapaper" all notifications allNotificationsList ¬
		default notifications enabledNotificationsList ¬
		icon of application "DevonTHINK Pro"
end tell

tell application "DEVONthink Pro"
	
	set selectedItems to selection
	
	show progress indicator "Adding articles to Instapaper..." steps (count of selectedItems)
	
	repeat with selectedItem in selectedItems
		
		set itemURL to URL of selectedItem
		
		if itemURL is not "" then
			
			set itemName to name of selectedItem
			
			step progress indicator
			
			set command to "python -c \"instapaper_username='" & username & "'; instapaper_password='" & pwd & "'; import httplib, urllib; params = urllib.urlencode( {'username': instapaper_username, 'password': instapaper_password, 'url': '" & itemURL & "', 'auto-title': '1' } ); headers = {'Content-type': 'application/x-www-form-urlencoded','Accept': 'text/plain'}; conn = httplib.HTTPConnection('www.instapaper.com'); conn.request('POST', '/api/add', params, headers); response = conn.getresponse(); print response.status, response.reason\""
			
			do shell script command
			
			-- remove this code to turn off Growl notification
			
			tell application "GrowlHelperApp"
				notify with name "Success Notification" title "Added to Instapaper!" description itemName application name "Add to Instapaper"
			end tell
			
		end if
		
	end repeat
	
	hide progress indicator
	
end tell

It works! Thanks!

Whoops - spoke too soon. It looks like it’s working, makes all the right noises, reports that it’s done it – but when I go to instapaper.com, there’s no sign of the articles I supposedly saved to it. Hmmm…

Worked for me here.

Working on my MBP too. Thanks for a great script. :slight_smile:

Perhaps a dumb question. But what do I do with this script? Where do I put it?

I’m brand new to DevonThink and still finding my way around this Mac o’ mine.

thanks!

@netmanchris

Choose whichever version, above, you want. Press “Select All” then copy (command-c).

Open AppleScript Editor app in /Applications/Utilities.

Create a new document, paste the clipboard and click “Compile” on the toolbar.

From AppleScript Editor save to ~/Library/Application Support/DEVONthink Pro 2/Scripts/My Scripts – the “MyScripts” folder is a folder you would create – call it whatever you want – where you put your own scripts so as to avoid having them overwritten if you update DEVONthink in the future. (Small risk, but good to avoid.)

After saving, then the script will appear within the Scripts menubar item in DEVONthink