Request: Post to Instapaper

Sharing and discussing custom actions for LaunchBar
Post Reply
dylanpetter
Posts: 7
Joined: Sat Oct 24, 2009 12:07 pm

Request: Post to Instapaper

Post by dylanpetter » Thu Jan 19, 2012 10:56 am

Hi Everyone, I've been looking for a script to post a URL to Instapaper. Does anyone know where I could find this? Thanks!

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Request: Post to Instapaper

Post by aristidesfl » Tue Jan 24, 2012 12:50 pm

I can do it for a beer

manfred
Objective Development
Objective Development
Posts: 561
Joined: Sat Jul 31, 2010 9:47 am
Location: Vienna
Contact:

Re: Request: Post to Instapaper

Post by manfred » Tue Jan 24, 2012 3:44 pm

Two scripts to post to Instapaper. Both of them are using Growl if installed (success & error messages), otherwise AppleScript dialogs to display errors.
For both scripts it is necessary to adjust USERNAME and PASSWORD. Therefore it is a good idea to save the scripts »run only«.
Screen Shot 2012-01-24 at 14.43.36 .png
Screen Shot 2012-01-24 at 14.43.36 .png (62.87 KiB) Viewed 6754 times


  • Send to Instapaper – Receives the URL via LaunchBar (e.g. select a URL press TAB and select the script)

    Code: Select all

    on handle_string(_url)
       set _username to "USERNAME" -- change to your username
       set _password to "PASSWORD" -- if you do not have a password, any value should work
       
       set _rtnCode to do shell script "curl -s --user " & _username & ":" & _password & " --data-urlencode url=" & _url & " https://www.instapaper.com/api/add"
       
       tell application "System Events" to set _growlIsRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
       
       if (_growlIsRunning) then
          growlRegister()
          growlNotify(_rtnCode)
       else
          if (_rtnCode is not equal to "201") then
             display dialog "Error " & _rtnCode & "

    Please visit:
    http://www.instapaper.com/api/simple"
          end if
       end if
    end handle_string

    -----------------------------------
    -- Growl Part
    -----------------------------------

    on growlRegister()
       tell application "Growl"
          register as application "LaunchBar" all notifications {"Success", "Error"} default notifications {"Success", "Error"} icon of application "LaunchBar.app"
       end tell
    end growlRegister

    on growlNotify(_rtnCode)
       if (_rtnCode is equal to "201") then
          set _gTitle to "Success"
          set _gText to "Saved link successfully"
       else if (_rtnCode is equal to "500") then
          set _gTitle to "Error"
          set _gText to "Please try again later."
       else if (_rtnCode is equal to "403") then
          set _gTitle to "Error"
          set _gText to "Authentication Error"
       else if (_rtnCode is equal to "400") then
          set _gTitle to "Error"
          set _gText to "Bad Access"
       else
          set _gTitle to "Error"
          set _gText to "Unkown Error"
       end if
       
       tell application "Growl"
          notify with name _gTitle title "Instapaper" description _gText application name "LaunchBar"
       end tell
    end growlNotify
  • Send Current Safari Page to Instapaper - Receives the URL from the active Safari Tab and posts it to Instapaper

    Code: Select all

    set _username to "USERNAME" -- change to your username
    set _password to "PASSWORD" -- if you do not have a password, any value should work

    tell application "LaunchBar" to hide
    tell application "System Events" to set _currentApplication to name of 1st application process whose frontmost is true
    set _currentURL to getCurrentURL(_currentApplication)

    if _currentURL is not "" then
       set _rtnCode to do shell script "curl -s --user " & _username & ":" & _password & " --data-urlencode url=" & _currentURL & " https://www.instapaper.com/api/add"
       
       tell application "System Events" to set _growlIsRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
       
       if (_growlIsRunning) then
          growlRegister()
          growlNotify(_rtnCode)
       else
          if (_rtnCode is not equal to "201") then
             display dialog "Error " & _rtnCode & "

    Please visit:
    http://www.instapaper.com/api/simple"
          end if
       end if
    end if


    on getCurrentURL(currentApp)
       tell application "Safari" to set currentURL to URL of current tab of window 1
       return currentURL
    end getCurrentURL

    -----------------------------------
    -- Growl Part
    -----------------------------------

    on growlRegister()
       tell application "Growl"
          register as application "LaunchBar" all notifications {"Success", "Error"} default notifications {"Success", "Error"} icon of application "LaunchBar.app"
       end tell
    end growlRegister

    on growlNotify(_rtnCode)
       if (_rtnCode is equal to "201") then
          set _gTitle to "Success"
          set _gText to "Saved link successfully"
       else if (_rtnCode is equal to "500") then
          set _gTitle to "Error"
          set _gText to "Please try again later."
       else if (_rtnCode is equal to "403") then
          set _gTitle to "Error"
          set _gText to "Authentication Error"
       else if (_rtnCode is equal to "400") then
          set _gTitle to "Error"
          set _gText to "Bad Access"
       else
          set _gTitle to "Error"
          set _gText to "Unkown Error"
       end if
       
       tell application "Growl"
          notify with name _gTitle title "Instapaper" description _gText application name "LaunchBar"
       end tell
    end growlNotify

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Request: Post to Instapaper

Post by aristidesfl » Tue Jan 24, 2012 3:51 pm

can't this be done using the token provided in the bookmarklet instead of user/pass?

manfred
Objective Development
Objective Development
Posts: 561
Joined: Sat Jul 31, 2010 9:47 am
Location: Vienna
Contact:

Re: Request: Post to Instapaper

Post by manfred » Tue Jan 24, 2012 4:45 pm

I don't think it is possible to use the bookmarklet token with Instapaper's API. But if you find a way to do so, please let me know!

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Request: Post to Instapaper

Post by aristidesfl » Tue Jan 24, 2012 5:04 pm

how would the bookmarklet / browser extensions work then?

manfred
Objective Development
Objective Development
Posts: 561
Joined: Sat Jul 31, 2010 9:47 am
Location: Vienna
Contact:

Re: Request: Post to Instapaper

Post by manfred » Tue Jan 24, 2012 5:12 pm

The bookmarklet displays a login page if you are not logged in.

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Request: Post to Instapaper

Post by aristidesfl » Tue Jan 24, 2012 5:23 pm

hmm. cookies then

manfred
Objective Development
Objective Development
Posts: 561
Joined: Sat Jul 31, 2010 9:47 am
Location: Vienna
Contact:

Re: Request: Post to Instapaper

Post by manfred » Thu Jan 26, 2012 4:10 pm

Of course it might be possible to use the bookmarklet in conjunction with a browser specific »do javascript« command. But I think using the Instapaper API is a better way to deal with this issue. If you are afraid of saving your password in an AppleScript, it is possible to load it from the keychain as well.

  • Since Lion dropped the official keychain scripting support, you need to install Usable Keychain Scripting first. Just copy the file ~/Library/ScriptingAdditions
  • Open your keychain and add a new item for your instapaper password:
    Screen Shot 2012-01-26 at 15.02.57 .png
    Screen Shot 2012-01-26 at 15.02.57 .png (69.32 KiB) Viewed 6712 times
  • Take the script from my previous post and append the following part to the end:

    Code: Select all

    on loadPasswordFromKeychain(_url)
       tell application "Usable Keychain Scripting" to tell current keychain
          return password of first internet password whose protocol is HTTP and name is _url
       end tell
    end loadPasswordFromKeychain
  • In addition, change the third line from

    Code: Select all

       set _password to "PASSWORD" -- if you do not have a password, any value should work
    to

    Code: Select all

       set _password to loadPasswordFromKeychain("www.instapaper.com")

Post Reply