Ticket #28531: patch-pastebinit-pbcopy.diff

File patch-pastebinit-pbcopy.diff, 1.5 KB (added by BlackFrog1, 14 years ago)

to copy url to clipboard

  • pastebinit

    old new  
    160160    def getFirstNodeText(nodes, title):
    161161        return getText(getFirstNode(nodes, title).childNodes)
    162162
     163    # Use Mac OS X pbcopy to paste url to clipboard
     164    def copyToClipboard(url):
     165        clipboard = os.popen("pbcopy", "w")
     166        clipboard.write(url)
     167        clipboard.close()
     168
    163169    # Display usage instructions
    164170    def Usage():
    165171        print "pastebinit v" + version
     
    331337    page = url_opener.open(website, params) #Send the informations and be redirected to the final page
    332338
    333339    try:
     340        pasteURL = "" # the url of where we can file the paste
    334341        if reLink: #Check if we have to apply a regexp
    335342            website = website.replace(tmp_page, "")
    336343            if reLink == '(.*)':
    337                 print page.read().strip()
     344                pasteURL = page.read().strip()
    338345            else:
    339                 print website + re.split(reLink, page.read())[1] #Print the result of the Regexp
     346                pasteURL = website + re.split(reLink, page.read())[1] #Print the result of the Regexp
    340347        else:
    341             print page.url #Get the final page and show the ur
     348            pasteURL = page.url #Get the final page and show the url
     349       
     350        # copy the url to the clipboard
     351        copyToClipboard(pasteURL)
     352        print pasteURL # output paste url to stdout
     353       
    342354    except KeyboardInterrupt:
    343355        sys.exit(_("KeyboardInterrupt caught."))
    344356    except: