V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
larkifly
V2EX  ›  Python

os x 环境下, python 如何获取到剪切板的内容?

  •  
  •   larkifly · 2016-01-11 12:57:57 +08:00 · 3922 次点击
    这是一个创建于 3027 天前的主题,其中的信息可能已经有所发展或是发生改变。
    9 条回复    2016-01-11 20:07:27 +08:00
    aisk
        1
    aisk  
       2016-01-11 13:05:24 +08:00   ❤️ 1
    可以尝试调用命令行的 pbpaste ,其他方案就不清楚了。
    kfll
        2
    kfll  
       2016-01-11 13:05:31 +08:00   ❤️ 1
    调子进程 pbpaste
    ClericPy
        3
    ClericPy  
       2016-01-11 13:25:32 +08:00   ❤️ 1
    pyperclip
    myth
        4
    myth  
       2016-01-11 13:43:51 +08:00   ❤️ 1
    PySide or PyQt4

    QtGui.QApplication.clipboard()
    Elethom
        5
    Elethom  
       2016-01-11 13:49:19 +08:00   ❤️ 2
    兩種方式:
    * 開 subprocess 讀 pbpaste 的 stdout ,同理用 pbcopy 可以寫入 clipboard ;
    * PyObjC 直接 call NSPasteboard 的 API 。
    aec4d
        6
    aec4d  
       2016-01-11 14:09:54 +08:00
    如果只是要获取粘贴板里面的字符串 那么 python 有很多库可以做(底层都是对 pbpaste 的封装)
    如果是要获取粘贴板里面的图片 可以用 pngpaste
    我写过一个上传粘贴板图片的脚本
    https://gist.github.com/Ficapy/8c57998d14c434ab5df3
    vanxining
        7
    vanxining  
       2016-01-11 14:12:16 +08:00 via Android
    pip install clipboard
    FradSer
        8
    FradSer  
       2016-01-11 14:35:36 +08:00
    @Elethom 谢谢爱酱
    cxbig
        9
    cxbig  
       2016-01-11 20:07:27 +08:00
    学用命令行的 pbcopy 和 pbpaste
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3515 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 04:50 · PVG 12:50 · LAX 21:50 · JFK 00:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.