试了下 pbpaste命令,貌似只能打印出剪切板里的文本
|  |      1ysc3839      2021-07-14 15:03:45 +08:00 用 Swift 写个命令行工具,然后 Node.js 调用吧。 | 
|  |      2james2013      2021-07-14 15:32:28 +08:00 如下是使用 js  和 vue 从剪切板获取图片对象,实测可用.转成 base64 需要自己处理 getImage() { const clipboardObj = navigator.clipboard; if (clipboardObj !== undefined) { setTimeout(async () => { try { const clipboardItems = await navigator.clipboard.read(); for (const clipboardItem of clipboardItems) { // console.log(clipboardItem); for (const type of clipboardItem.types) { const blob = await clipboardItem.getType(type); console.log(blob); if(blob.type.includes("image")){ this.imageUrl = URL.createObjectURL(blob); return }else{ console.log("not image"); } } } this.$message({ message: '剪切板没有图片', type: 'warning', duration: 2000 }); } catch (err) { console.error(err.name, err.message); } }, 100); } }, | 
|  |      3xqin      2021-07-14 15:41:19 +08:00 google 关键字  pngpaste | 
|      4JasonEWNL      2021-07-14 16:14:33 +08:00 pbpaste 已经接近可用的思路了,可以参照下面的方案写个函数存在 .*shrc 里: openssl base64 < path/to/file.png | tr -d '\n' | pbcopy cat path/to/file.png | openssl base64 | tr -d '\n' | pbcopy | 
|  |      5magicdawn      2021-07-27 18:44:40 +08:00 https://github.com/magicdawn/simple-mac-clipboard 和 Electron clipboard 差不多的 api, 之前做 electron, 碰到读图片导致 electron crash. 写了个 addon, 可以在 node or electron 中使用 const clip = require('simple-mac-clipboard') const buf = clip.readBuffer('public/png') // png buffer const base64 = buf.toString('base64') // png buffer -> string (base64 encoding) | 
|  |      6magicdawn      2021-07-27 18:56:05 +08:00 | 
|  |      7magicdawn      2021-07-27 18:57:36 +08:00 |