0

I want to copy a file in order to paste it later back into an application. I want to copy it exactly like I would do it manually (not only the content of that file).

import childProcess from 'child_process';
const filePath = 'my-file.extension';
const exec = childProcess.exec;
// Execute the appropriate command to copy the file to the clipboard
if (process.platform === 'darwin') {
    // macOS
    exec(`pbcopy < "${filePath}"`);
} else if (process.platform === 'win32') {
    // Windows
    exec(`clip < "${filePath}"`);
}
console.log('File copied to clipboard!');
Andi Giga
  • 3,744
  • 9
  • 38
  • 68

0 Answers0