fredag 23 april 2010

Send text to Mac ClipBoard from python (like pbcopy)

def sendToClipBoard(string):
    from AppKit import NSPasteboard,NSObject,NSStringPboardType
    pasteboard = NSPasteboard.generalPasteboard()
    emptyOwner = NSObject.alloc().init()
    pasteboard.declareTypes_owner_([NSStringPboardType], emptyOwner)
    pasteboard.setString_forType_(string, NSStringPboardType)

if __name__ == "__main__":
    import sys

Idea from this marvellous post about writing a SIMBL plugin in Python.

About the building the TabDump plugin:
When I built the SIMBL plugin, I had to compile it with
/usr/bin/python py2app
and I had to set MaxBundleVersion='6531' in

Anothere way is to build it with
/usr/bin/python py2app -s --site-packages
It doesn't copy in 16 MB python stuff into the bundle.

For some reason /opt/local/bin/python doesn't work, because
then py2app makes only a i368 binary, not a x86_64 binary.  Weird.

Inga kommentarer:

Skicka en kommentar