Created
April 17, 2014 21:41
-
-
Save mkremins/11013151 to your computer and use it in GitHub Desktop.
node.js: put text into OS X clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pbcopy(data) { | |
var proc = require('child_process').spawn('pbcopy'); | |
proc.stdin.write(data); | |
proc.stdin.end(); | |
} |
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
Thanks mate saved my day