简体   繁体   English

xsel -o 等效于 OS X

[英]xsel -o equivalent for OS X

Is there an equivalent solution to grab selected text in OS X as 'xsel -o' works for Linux?是否有等效的解决方案可以在 OS X 中抓取所选文本,因为“xsel -o”适用于 Linux?

Just need the current selection so I can use the text in shell script.只需要当前选择,这样我就可以使用 shell 脚本中的文本。

Cheers, Erik干杯,埃里克

You can probably install xsel on MacOS.您可能可以在 MacOS 上安装xsel (UPDATE: According to Arkku's comment, that will only work if you have the X11 server running and synchronized to the OS X pasteboard.) (更新:根据 Arkku 的评论,这仅在您运行 X11 服务器并同步到 OS X 粘贴板时才有效。)

If not, a quick Google search turns up pbcopy / pbpaste , which apparently is pre-installed.如果没有,快速的谷歌搜索就会出现pbcopy / pbpaste ,这显然是预先安装的。

Link: https://github.com/raymontag/keepassc/issues/59链接: https : //github.com/raymontag/keepassc/issues/59

The Linux tool xsel is not required as pbcopy and pbpaste are Apple command line utilities that provide this functionality and are installed by default on macOS. Linux 工具xsel不是必需的,因为pbcopypbpaste是提供此功能的 Apple 命令行实用程序,并且默认安装在 macOS 上。

From the manual page ( man pbcopy ):从手册页( man pbcopy ):

pbcopy, pbpaste - provide copying and pasting to the pasteboard (the Clipboard) from command line pbcopy, pbpaste - 从命令行提供复制和粘贴到粘贴板(剪贴板)

pbcopy takes the standard input and places it in the specified pasteboard. pbcopy 接受标准输入并将其放置在指定的粘贴板中。 If no pasteboard is specified, the general pasteboard will be used by default.如果未指定粘贴板,则默认使用通用粘贴板。 The input is placed in the pasteboard as plain text 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.输入作为纯文本数据放置在粘贴板中,除非它以封装 PostScript (EPS) 文件头或富文本格式 (RTF) 文件头开头,在这种情况下,它作为这些数据类型之一放置在粘贴板中。

pbpaste removes the data from the pasteboard and writes it to the standard output. pbpaste 从粘贴板上删除数据并将其写入标准输出。 It normally looks first for plain text data in the pasteboard and writes that to the standard output;它通常首先在粘贴板中查找纯文本数据并将其写入标准输出; if no plain text data is in the pasteboard it looks for Encapsulated PostScript;如果粘贴板中没有纯文本数据,它会寻找封装的 PostScript; if no EPS is present it looks for Rich Text.如果不存在 EPS,则它会查找富文本。 If none of those types is present in the pasteboard, pbpaste produces no output.如果粘贴板中不存在这些类型,则 pbpaste 不会产生任何输出。

To copy filename.txt to the clipboard, use the following:要将filename.txt复制到剪贴板,请使用以下命令:

pbcopy < filename.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM