Copy to clipboard in NodeJS?

A clipboard is not inherent to an operating system. It's a construct of whatever window system the operating system happens to be running. So if you wanted this to work on X for example, you would need bindings to Xlib and/or XCB.

Xlib bindings for node actually exist: https://github. Com/mixu/nwm Although I'm not sure whether it gives you access to the X clipboard, you might end up writing your own. You'll need separate bindings for windows.

A clipboard is not inherent to an operating system. It's a construct of whatever window system the operating system happens to be running. So if you wanted this to work on X for example, you would need bindings to Xlib and/or XCB.

Xlib bindings for node actually exist: https://github. Com/mixu/nwm. Although I'm not sure whether it gives you access to the X clipboard, you might end up writing your own.

You'll need separate bindings for windows. Edit: If you want to do something hacky, you could also use xclip: var exec = require('child_process'). Exec; var getClipboard = function(func) { exec('/usr/bin/xclip -o -selection clipboard', function(err, stdout, stderr) { if (err || stderr) return func(err || new Error(stderr)); func(null, stdout); }); }; getClipboard(function(err, text) { if (err) throw err; console.

Log(text); }).

I managed to do so by creating a different application which handles this. It's certainly not the best way, but it works. I'm on Windows and created a VB.NET application: Module Module1 Sub Main() Dim text = My.Application.

CommandLineArgs(0) My.Computer.Clipboard. SetText(text) Console. Write(text) ' will appear on stdout End Sub End Module Then in Node.

Js, I used child_process. Exec to run the VB.NET application, with the data to be copied passed as a command line argument: require('child_process'). Exec( "CopyToClipboard.

Exe \"test foo bar\"", function(err, stdout, stderr) { console. Log(stdout); // to confirm the application has been run } ).

Writing an app for this means I need to compile it for Mac, Linux and Windows. – rFactor Oct 15 at 17:15 @rFactor: I've no experience with Mac/Linux at all I'm afraid, and I'm not aware of a built-in clipboard command. – pimvdb Oct 15 at 17:22.

Mac has a native command line pbcopy for this usecase: require('child_process'). Exec( 'echo "test foo bar" | pbcopy', function(err, stdout, stderr) { console. Log(stdout); // to confirm the application has been run } ); Same code for Linux but replace pbcopy with Xclip (apt get install xclip).

Interesting! Do you think there's a Windows way to do this also? And what about bundling xclip in my program as I wouldn't want to ask the user to install xclip.

– rFactor Oct 16 at 11:45 I found there's something in Windows: echo fooo | clip. Now, how to have this in Linux without asking the user to install something? – rFactor Oct 16 at 11:52.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions