且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python获取Mac剪贴板内容

更新时间:2022-03-18 14:54:28

PyObjC是必经之路:

PyObjC is the way to go:

#!/usr/bin/python

from AppKit import NSPasteboard, NSStringPboardType

pb = NSPasteboard.generalPasteboard()
pbstring = pb.stringForType_(NSStringPboardType)
print u"Pastboard string: %s".encode("utf-8") % repr(pbstring)

这仅支持文本,否则将返回None.您也可以扩展它以支持其他数据类型,请参见

This only supports text and will return None otherwise. You can extend it to support other data types as well, see NSPastboard Class Reference.