A command line utility that allows read/write (i.e copy/paste) access to the system clipboard. It does this by wrapping
pbcopy/pbpaste (for OSX),
xclip (for Linux and OpenBSD), and
clip (for Windows). Currently works with node.js v0.8+.
require("copy-paste") is executed, an object with the following properties is returned:
copy(text[, callback]): asynchronously replaces the current contents of the clip board with
text. Takes either a string, array, object, or readable stream. Returns the same value passed in. Optional callback will fire when the copy operation is complete.
paste([callback]): if no callback is provided,
pastesynchronously returns the current contents of the system clip board. Otherwise, the contents of the system clip board are passed to the callback as the second parameter.
Note: The synchronous version of
pasteis not always availabled. Unfortunately, I'm having a hard time finding a synchronous version of
child_process.execthat consistently works on all platforms, especially windows. An error message is shown if the synchronous version of
pasteis used on an unsupported platform. That said, the asynchronous version of
pasteis always available.
pasteto the global namespace. Returns an object with
The easiest way to get node-copy-paste is with npm:
npm install -g copy-paste
Alternatively you can clone this git repository:
git clone git://github.com/xavi-/node-copy-paste.git
I'm hoping to add various fallbacks for instances when
clip is not avaiable (see experimental-fallbacks branch). Also this library needs to be more thoroughly tested on windows.
- Xavi Ramirez
This project is released under The MIT License.