简体   繁体   中英

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.

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?

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 code:

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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