AppleScript to paste text from clipboard into file

I thought it would be easy. Google makes me think differently.

What I want is a bad client clipboard. Everything I've watched on the net is either not free, not a single application that should cost anyone something simple, or incompatible with local Linux or Windows installations or some of those.

In a better solution, a right mouse action was added for "cut", "copy" and "paste" named "copy to file". The file may or may not exist, but will have a fixed name and reside on a shared disk.

I think I'll need a second right mouse action "Paste from file" to complete "copy to file".

So, will anyone show me how to have AppleScript, or maybe Automator, take the current text content of the clipboard and paste into an existing file, overwriting any existing file content?

OS / X Snow Leopard

Thank.

+3


source to share


1 answer


how to get AppleScript [...], take current clipboard text content and paste into existing file, overwriting any existing file content

AppleScript code:

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

      

To read text from a file back to the clipboard, use



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

      

For documentation see man pbpaste

EDIT: Now to convert AppleScript to Mac OS X Service , which will appear in the Services group of each context menu (right click / CTRL + click any text), you can use Automator as described in this tutorial .

+5


source







All Articles