Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 643
Wes Miller Avatar asked Oct 23 '25 17:10

Wes Miller


1 Answers

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.

like image 189
fanaugen Avatar answered Oct 26 '25 06:10

fanaugen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!