简体   繁体   English

AppleScript将剪贴板中的文本粘贴到文件中

[英]AppleScript to paste text from clipboard into a file

I thought this would be easy. 我觉得这很容易。 The Google makes me think otherwise. 谷歌让我想到了。

What I want is a poor man's inter-OS clipboard. 我想要的是一个穷人的操作系统间剪贴板。 Everything I looked at on the net is either not free, no app this simple should cost anybody anything, or isn't compatible with local linux installs or Windows or some such. 我在网上看到的一切都不是免费的,没有应用程序这个简单应该花费任何人,或与本地Linux安装或Windows或其他一些不兼容。

In the best solution a right mouse action would be added to "cut", "copy" and "paste" named something like "copy to file". 在最佳解决方案中,右键鼠标操作将添加到“剪切”,“复制”和“粘贴”,其名称类似于“复制到文件”。 The file might or might not exist but would have a fixed name and be on a shared disk. 该文件可能存在也可能不存在,但具有固定名称并位于共享磁盘上。

I guess I'd need a second right mouse action "Paste from file" to complement the "copy to file". 我想我需要第二个鼠标右键动作“从文件粘贴”以补充“复制到文件”。

So, would some one show me how to have an AppleScript or, maybe, Automator, take the current text contents of the clipboard and paste into an existing file, overwriting any existing contents of the file? 那么,有人会告诉我如何使用AppleScript或者Automator,获取剪贴板的当前文本内容并粘贴到现有文件中,覆盖文件的任何现有内容吗?

OS/X Snow Leopard OS / X Snow Leopard

Thanks. 谢谢。

how to have an AppleScript […], take the current text contents of the clipboard and paste into an existing file, overwriting any existing contents of the file 如何拥有AppleScript [...],获取剪贴板的当前文本内容并粘贴到现有文件中,覆盖文件的任何现有内容

AppleScript code: AppleScript代码:

do shell script "pbpaste > /path/to/your/clipboard-file.txt"

In order to read text from the file back into the clipboard, use 为了将文件中的文本读回到剪贴板,请使用

do shell script "cat /path/to/your/clipboard-file.txt | pbcopy"

For documentation, see man pbpaste 有关文档,请参阅man pbpaste

EDIT: Now, to convert the AppleScript into a Mac OS X Service , which will appear in the "Services" group of every context menu (at right-click / CTRL+click on any text), you can use Automator, as described in this tutorial . 编辑:现在,要将AppleScript转换为Mac OS X 服务 ,它将显示在每个上下文菜单的“服务”组中(右键单击/ CTRL +单击任何文本),您可以使用Automator,如本教程

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

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