Use pastie.org with LaunchBar

Since a while, I’m having senile insomnia, so I thought, I should use it for good. One thing that always bugs me at work is the work with pastie (or any other paste-thing) because of the copy – paste – copy thing.
So I wrote a very little script to use it with LaunchBar.

What does it do? It takes your clipboard, pastes it to pastie and pastes the returned URL back into the clipboard..

Here is the script:

pastie.scpt

set pastieURL to "http://pastie.org/pastes"
try
set responseURL to (do shell script "curl http://pastie.caboo.se/pastes/create -H 'Expect:' -F 'paste[parser]=plaintext' -F 'paste[body]=" & (the clipboard) & "' -F 'paste[authorization]=burger' -s -L -o /dev/null -w '%{url_effective}'")
set the clipboard to responseURL
end try

Save this to “~/Library/Application Support/LaunchBar/Actions/” (works with LaunchBar 5) and it will detect it automatically. Type the name of your script and you’re done. So much for my insomnia :)

UPDATE: Just found out about Spark which let’s you define shortcuts for Apple Scripts – which is another nice way.

11 Comments to Use pastie.org with LaunchBar

  1. January 8, 2009 at 9:02 am Permalink
    ebi's Gravatar ebi

    Awesome! :) A little more feedback like when it’s ready to get pasted again would be even nicer :)

  2. February 26, 2009 at 1:27 am Permalink
    Ben D.'s Gravatar Ben D.

    Is there a way to make the resulting pastie a “private” one? Sometimes I’m pasting things I may not want in the public “All” stream of pastie’s.

  3. February 27, 2009 at 2:40 pm Permalink
    marc's Gravatar marc

    Ben D.: I guess so.. just add -F ‘paste[restricted] = 1′

  4. February 27, 2009 at 9:56 pm Permalink
    Ben D.'s Gravatar Ben D.

    marc,

    Thanks so much for the reply. However, I tried it and it doesn’t seem to work. It is still making the pastie just fine, but it doesn’t make a private one. I tried using paste[private]=1 but that didn’t work either. Any other thoughts?

    Thanks for your help and the great script!

    Ben

  5. July 21, 2009 at 6:57 pm Permalink
    Eric Steele's Gravatar Eric Steele

    Just wanted to thank you for this. I found it very useful.

    One small addition I made was to stick the pastie url back into LaunchBar so that I could either open it with a quick enter or send it elsewhere.

    tell application “LaunchBar”
    set selection to responseURL
    end tell

  6. August 16, 2009 at 10:20 pm Permalink
    Todd's Gravatar Todd

    Hi,

    I created the script and can see it in LB but geez, I really feel like an idiot, how exactly do I use this? Kinda new to LB.

  7. August 28, 2009 at 10:17 am Permalink

    @ebi

    Some opitions for feedback (with LaunchBar):

    - Return URL to LaunchBar (already mentioned by Eric):
    tell application “LaunchBar”
    set selection as text to responseURL
    end tell

    - Display Large Type:
    tell application “LaunchBar”
    display in large type “Done! URL: ” & responseURL as text
    delay 0.5
    hide
    end tell

  8. August 28, 2009 at 10:50 am Permalink
    Christian's Gravatar Christian

    s.th. is messed up tough … no linebreaks …http://qkpic.com/5b20d

  9. January 24, 2010 at 2:11 am Permalink
    Scott's Gravatar Scott

    Looking around for how to do this, I wanted to thank you for saving me the curl mess and deciding what I need to pass along. I am stumped, and have too many hours into debugging this, so I am coming back here.

    If you take your script, and put it into AppleScript Editor, you can then beat up on the pastie.org servers with a command-R or clicking run. Have you run into the cases certain code will not post?

    I added an on error to the try statement, and display the error, which is usually just a mess of curl code. display dialog sort of sucks for debugging, and is height limited to my screen. I do not not any other way to debug, not being an AppleScript master.

    I have tried using quoted form, adding in curl args for url encoding the data, and a lot more, nothing is getting me past being able to post the most basic of code snippets.

    Here is what I have done to your code, to help me with the errors

    set pastieURL to “http://pastie.org/pastes”
    try
    set responseURL to (do shell script “curl http://pastie.caboo.se/pastes/create -H ‘Expect:’ -F ‘paste[parser]=plaintext’ -F ‘paste[body]=” & (the clipboard) & “‘ -F ‘paste[authorization]=burger’ -s -L -o /dev/null -w ‘%{url_effective}’”)
    set the clipboard to responseURL

    do shell script “echo ‘all went well’ >> ~/Desktop/error.as.txt”
    on error errMsg number errNum
    do shell script “echo ‘” & errMsg & “‘ >> ~/Desktop/error.as.txt”
    display dialog “Error Number: ” & errNum & “Error Message: ” & errMsg
    end try

    All you need to do is copy
    example@example.com

    Then move to the AppleScript Editor and press command-R. That will not post, it is the greater than and less than symbols that get it hung up. html entity encoding solves that, but who wants their code altered that way?

    That is the simplest case I can distill it down to. There are others, where the difference in ” and ‘ are a problem, and I believe the entire copied string will need to be url encoded. I have tried –data content-type application/x-www-form-urlencoded, –data-encode etc. Probably the first time I read the entire man page on curls section on POST of data, since I am usually pulling data away from someone, not mimicking an http post/get

    I have worked on a LaunchBar script that will post to pastie, show you a 10 line snip of the code you are about to post, dealing with the \r and \n issue in display dialog, and then error trapping and checking the entire thing. I use a copy of that code to actually try to sent to pastie, which is where I first started to track this down.

    A pretty reoccurring theme in the error, is to show me the entire copied string, along with a mess of data from curl, and this in my AppleScript Editor result log window at the bottom:

    error “sh: -c: line 0: unexpected EOF while looking for matching “’
    sh: -c: line 1: syntax error: unexpected end of file” number 2
    If you take any large block of code, read it in from a file, and send it off to do shell script with curl, something is going to bail out.

    I am thinking, a better method may be to take the copied clipboard, write it out to /tmp/whatever.txt, and then running whatever commands you need to on it to massage the quotes, url encodings, etc, and read it back in. I am yet to find a simple way to url encode data aside from creating a case where this is not going to be a self contained script. I absolutely do not want this to need OSAX, shell scripts, etc. Just one AppleScript, or do it all in one shell scrip that I can call from LaunchBar, I would be ok with that as well. That actually may be better, as it would be faster, since LaunchBar and AppleScript sort of suck in combination at times.

    Examples of data that will not go from clipboard to pastie with your curl command:
    http://pastie.org/791797
    http://pastie.org/791799
    http://pastie.org/791800

    I may end up taking this to an AppleScript mailing list, unless you have some suggestions. I would like to show you where I have gotten this “post to pastie” script to go, but want it to work first.

    Thanks for any suggestions or pointers. I will post back if I find anything out.

  10. January 24, 2010 at 2:17 am Permalink
    Scott's Gravatar Scott

    Sorry, I used pre and I think blockquote, but that post did not come out looking how it was supposed to. I guess html is not supported here?

Dare to comment?