开发者

Set clipboard to image - pbcopy

How do you set an image as the clipboard with pbcopy?

This doesn't work:

cat image.png | pb开发者_如何转开发copy


Updated Answer

You can actually put a JPEG image in the clipboard using Applescript like this at the command-line:

osascript -e 'set the clipboard to (read (POSIX file "/Users/mark/Desktop/a.jpg") as JPEG picture)'

You can then check what is on the clipboard with:

osascript -e 'clipboard info'

JPEG picture, 175960, «class 8BPS», 641904, GIF picture, 124637, «class jp2 », 102086, TIFF picture, 1481282, «class PNGf», 412940, «class BMP », 1477734, «class TPIC», 609835

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:

# Copy image to clipboard
uuencode SomeFile.jpg - | pbcopy

and uudecode when going back the other way

# Paste from clipboard to image file
pbpaste | uudecode -o AnotherFile.jpg


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:

cat image.png | impbcopy -


From the documentation:

The input is placed in the pasteboard as ASCII data unless it begins with the Encapsulated PostScript (EPS) file header or the Rich Text Format (RTF) file header, in which case it is placed in the pasteboard as one of those data types.

It doesn't sound like image data is supported, so it won't work.


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:

osascript -e 'set the clipboard to (read (POSIX file "/Users/mark/Desktop/a.png") as  {«class PNGf»})'


one alternative that works for both images and animated gif is:

osascript -e 'tell app "Finder" to set the clipboard to ( POSIX file "<PATH_TO_IMAGE>" )'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜