Last active
March 26, 2024 02:11
-
-
Save psenger/cef189aa928e55c2d5953fe8dfe3f19a to your computer and use it in GitHub Desktop.
[How to programmatically get data in JavaScript directly into your buffer] #MacOS #JavaScript #Node
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
/** | |
* Sends a String of data to the Mac OSX Buffer, this is very helpful if | |
* you are doing something in scratch pad and want to copy it somewhere. | |
* | |
* this beats Pipe-ing the output to pbcopy directly. | |
* | |
* @param {string} data - Required UTF-8 String to be copied to the buffer. | |
* | |
* @return {void} | |
* | |
* @example | |
* pbcopy(JSON.stringify(data, null, 4)) | |
*/ | |
function pbcopy(data) { | |
const proc = require('child_process').spawn('pbcopy', { env: { LC_CTYPE: 'UTF-8' } }) | |
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