Skip to content

Instantly share code, notes, and snippets.

@mkremins
Created April 17, 2014 21:41
Show Gist options
  • Save mkremins/11013151 to your computer and use it in GitHub Desktop.
Save mkremins/11013151 to your computer and use it in GitHub Desktop.
node.js: put text into OS X clipboard
function pbcopy(data) {
var proc = require('child_process').spawn('pbcopy');
proc.stdin.write(data);
proc.stdin.end();
}
@SlideeScherz
Copy link

windows

Basic demo, but should be ~promisified

function clipboardTransport(data) {
  let clipCommand = process.platform === 'win32' ? 'clip' : 'pbcopy';

  const proc = spawn(clipCommand);
  proc.on('close', () => console.log('Copied to clipboard'));
  proc.on('error', console.error);

  proc.stdin.write(data);
  proc.stdin.end();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment