Fixing osascript clipboard for OSX Mountain Lion
===

In my Ruby application, I've used the following function for a long time to write to the clipboard:


    def pbcopy(text)
      IO.popen("osascript -e 'set the clipboard to do shell script \"cat\"'","w+") {|pipe| pipe << text}
    end

I got this code from [here][1], and it replaced my earlier use of pbpaste through backticks, because it seemed much more reliable with UTF8 and other things. It has always worked perfectly, however with the new OSX Mountain Lion, it stopped working. osascript -e 'set the clipboard to "hi"' works well, so it might be something with the piping that doesn't work. Any help would be much appreciated!


  [1]: http://www.coderaptors.com/?action=browse&diff=1&id=Random_tips_for_Mac_OS_X