• jeromecarney

    Jon - thanks, you set me on the right track -- the app I want to paste into (MarginNote) accepts rich text only if it's formatted as an Apple Web Archive type. Here's how I ultimately got it to work for Python 2.7, thanks to this guide on coercing HTML into an archive type:

    from objc_util import * 
    import os
    import base64
    theDefinition = '<html><head></head><body>''<font size="5">' + '<b>Hello</b> <i>world!2</i>' + '</font></body></html>'
    theData = base64.encodestring(theDefinition)
    theData = str(theData)
    theArchive = """<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
     <dict>
      <key>WebMainResource</key>
      <dict>
       <key>WebResourceData</key>
       <data>
       """ + theData + """   </data>
       <key>WebResourceFrameName</key>
       <string></string>
       <key>WebResourceMIMEType</key>
       <string>text/html</string>
       <key>WebResourceTextEncodingName</key>
       <string>UTF-8</string>
       <key>WebResourceURL</key>
       <string>about:blank</string>
      </dict>
     </dict>
    </plist>"""
    thePasteBoard = ObjCClass('UIPasteboard')
    thePasteBoard = thePasteBoard.generalPasteboard()
    theType = "Apple Web Archive pasteboard type"
    thePasteBoard.setValue_forPasteboardType_(theArchive,theType)
    

    posted in Pythonista read more
  • jeromecarney

    I've logged extensive hours working on a similar objective for the past two week -- outputting formatted text to the clipboard for a custom dictionary wrapper I've built for StarDict data -- but so far I've had no success.

    I've been able to coerce raw html into an rtf file, which I can then pass both to an NSData object as well as an attributed string, but there's still no way I can find -- UIPasteboard with every conceivable UTI, javascript, etc., to then send the formated data along to the clipboard. The current work around is to process the data throught Workflow, but that's slow and inelegant, especially when launched from split view.

    Is there anything in the works that would enable this functionality? It would seem to be such a basic feature.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!