Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use node modules instead of pbcopy directly #3

Open
ncordes1 opened this issue Sep 19, 2014 · 1 comment
Open

Use node modules instead of pbcopy directly #3

ncordes1 opened this issue Sep 19, 2014 · 1 comment

Comments

@ncordes1
Copy link

There are a few node modules that interact directly with the windows/OSX clipboard/pasteboard:

Windows:

OSX:

@lewisdonovan
Copy link

lewisdonovan commented Jul 29, 2019

There's a cross-system solution called clipboardy which can be implemented like so:

var fs   = require('fs')
var path = require('path')
var exec = require('child_process').exec
var argv = require('minimist')(process.argv.slice(2))
const clipboardy = require('clipboardy')

fs.readFile(path.join(__dirname, 'boilerplate.html'), function read(err, data) {
  if (err) return console.log(err)
  var filePath
  if ((filePath = argv.f) !== undefined) {
    if (filePath[0] !== "/") {
      filePath = path.join(process.cwd(),filePath)
    }
    fs.writeFile(filePath,data.toString(), function write(err,data) {
      if (err) return console.log(err)
      console.log("Boilerplate file created at " + filePath)
    })
  } else {
    clipboardy.writeSync(data.toString())
    console.log('Boilerplate code copied to clipboard.')
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants