将剪贴板设置为图像 - pbcopy
如何使用 pbcopy 将图像设置为剪贴板?
这不起作用:
cat image.png | pbcopy
How do you set an image as the clipboard with pbcopy?
This doesn't work:
cat image.png | pbcopy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
更新答案
实际上,您可以在命令行中使用 Applescript 将 JPEG 图像放入剪贴板,如下所示:
然后您可以使用以下命令检查剪贴板上的内容:
并且还将图像粘贴到文档中,使用通常的 ⌘-V。
原始答案
你可以做到这一点,不需要编译任何额外的软件,只需使用OS X中提供的工具。基本上,剪贴板无法存储二进制文件,所以你需要将您的二进制图像
uuencode
转换为简单的 ASCII 数据,如下所示:以及
uudecode
当以其他方式返回时Updated Answer
You can actually put a JPEG image in the clipboard using Applescript like this at the command-line:
You can then check what is on the clipboard with:
And also paste the image into a document, with the usual ⌘-V.
Original Answer
You can do this without needing to compile any additional software and just use the tools provided in OS X. Basically, the clipboard is unable to store binary, so you need to
uuencode
your binary image into simple ASCII data like this:and
uudecode
when going back the other way如前所述,这不适用于
pbcopy
,但您可以编写一些 Objective-C 程序来执行此操作:http://www.alecjacobson.com/weblog/?p=3816 。然后你可以发出:As stated, this won't work with
pbcopy
, but you can write a little objective-c program to do this: http://www.alecjacobson.com/weblog/?p=3816 . Then you can issue:从文档中:
听起来不支持图像数据,所以它不起作用。
From the documentation:
It doesn't sound like image data is supported, so it won't work.
如何将 PNG 图像复制到 Macos 剪贴板的实际(或最终)答案隐藏在 Mark 答案的注释中。由于从马克的回答中来看并不那么明显,而且我花了一段时间才找到它,所以我将其作为答案留在这里:
The actual (or final) answer to how to copy a PNG image into the macos' clipboard was hidden in the comments to the Mark's answer. As it is not (that) obvious from Mark's answer and it took me a while to find it I will leave it as an answer here:
一种同时适用于图像和 gif 动画的替代方法是:
one alternative that works for both images and animated gif is:
要使 osascript 正常工作(对于任何文件类型),请勿使用读取并使用绝对路径:
因此,对于当前目录中的文件(注意外部双引号):
To make osascript work properly (with any file type), don't use read and use absolute path:
So for a file in current directory (note outer double quotes):