GithubHelp home page GithubHelp logo

clipboardy's Introduction

clipboardy

Access the system clipboard (copy/paste)

Cross-platform. Supports: macOS, Windows, Linux, OpenBSD, FreeBSD, Android with Termux, and modern browsers.

Install

npm install clipboardy

Usage

import clipboard from 'clipboardy';

clipboard.writeSync('🦄');

clipboard.readSync();
//=> '🦄'

API

In the browser, it requires a secure context.

clipboard

.write(text)

Write (copy) to the clipboard asynchronously.

Returns a Promise.

text

Type: string

The text to write to the clipboard.

.read()

Read (paste) from the clipboard asynchronously.

Returns a Promise.

.writeSync(text)

Write (copy) to the clipboard synchronously.

Doesn't work in browsers.

text

Type: string

The text to write to the clipboard.

.readSync()

Read (paste) from the clipboard synchronously.

Doesn't work in browsers.

FAQ

Where can I find the source of the bundled binaries?

The Linux binary is just a bundled version of xsel. The source for the Windows binary can be found here.

Related

clipboardy's People

Contributors

abdulhannanali avatar andylnd avatar bendingbender avatar brandon93s avatar fisker avatar floatdrop avatar g-rath avatar ianpgall avatar mafintosh avatar richienb avatar rudloff avatar sebastianzaha avatar sindresorhus avatar stroncium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clipboardy's Issues

Probably doesn't work as expected on some Windows machines

node-copy-paste uses the same method of execing clip on Windows but I had some trouble with Unicode characters on systems running ASCII-only code pages (for instance, those configured with en-US locales).

I've addressed this in my fork of node-copy-paste by setting the code page to 65001 before running clip.exe.

execa might already be handling this but I'm not sure.

Not working in raspberry pi3

When I using this module in raspberry pi3, has exception:

Error: Both xsel and fallback failed
at makeError (/home/pi/test-rfid/node_modules/clipboardy/lib/linux.js:16:11)
at xselWithFallbackSync (/home/pi/test-rfid/node_modules/clipboardy/lib/linux.js:43:10)
at Object.copySync (/home/pi/test-rfid/node_modules/clipboardy/lib/linux.js:53:3)
at Object.exports.writeSync.text [as writeSync] (/home/pi/test-rfid/node_modules/clipboardy/index.js:39:14)
at Timeout._onTimeout (/home/pi/test-rfid/index.js:44:13)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)

Can't open display: (null) : Inappropriate ioctl for device

This happens only when I run my application as linux service. Executing my node app normally by "node main.js" works good.

Error Thrown at :

/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/lib/linux.js:43
throw makeError(xselError, fallbackError);
^

Full Error Stack :

            Error: Both xsel and fallback failed
                at makeError (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/lib/linux.js:16:11)
                at xselWithFallbackSync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/lib/linux.js:43:10)
                at Object.copySync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/lib/linux.js:53:3)
                at Object.exports.writeSync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/index.js:45:14)
                at Watcher.onChangeDetection (/home/mani/Desktop/mani/tools/screenshot-easy/main.js:85:16)
                at Watcher.emit (events.js:310:20)
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:305:19
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:39:7
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:303:7
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:109:10 {
            xselError: Error: Command failed: xsel --clipboard --input
            xsel: Can't open display: (null)
            : Inappropriate ioctl for device
            
            
                at makeError (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/execa/index.js:174:9)
                at Function.module.exports.sync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/execa/index.js:338:15)
                at xselWithFallbackSync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/lib/linux.js:38:16)
                at Object.copySync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/lib/linux.js:53:3)
                at Object.exports.writeSync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/index.js:45:14)
                at Watcher.onChangeDetection (/home/mani/Desktop/mani/tools/screenshot-easy/main.js:85:16)
                at Watcher.emit (events.js:310:20)
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:305:19
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:39:7
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:303:7 {
                code: 1,
                stdout: '',
                stderr: "xsel: Can't open display: (null)\n: Inappropriate ioctl for device\n",
                failed: true,
                signal: null,
                cmd: 'xsel --clipboard --input',
                timedOut: false
            },
            fallbackError: Error: Command failed: /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/fallbacks/linux/xsel --clipboard --input
            /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/fallbacks/linux/xsel: Can't open display: (null)
            : Inappropriate ioctl for device
            
            
                at makeError (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/execa/index.js:174:9)
                at Function.module.exports.sync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/execa/index.js:338:15)
                at xselWithFallbackSync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/lib/linux.js:41:17)
                at Object.copySync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/lib/linux.js:53:3)
                at Object.exports.writeSync (/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/index.js:45:14)
                at Watcher.onChangeDetection (/home/mani/Desktop/mani/tools/screenshot-easy/main.js:85:16)
                at Watcher.emit (events.js:310:20)
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:305:19
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:39:7
                at /home/mani/Desktop/mani/tools/screenshot-easy/node_modules/node-watch/lib/watch.js:303:7 {
                code: 1,
                stdout: '',
                stderr: "/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/fallbacks/linux/xsel: Can't open display: (null)\n" +
                ': Inappropriate ioctl for device\n',
                failed: true,
                signal: null,
                cmd: '/home/mani/Desktop/mani/tools/screenshot-easy/node_modules/clipboardy/fallbacks/linux/xsel --clipboard --input',
                timedOut: false
            }
            }

Add events

Could you guys add events like clipboardy.on('paste')?
So it triggers a callback with the data pasted

UncaughtSyntaxError: Unexpected token import

Error info:

UncaughtSyntaxError: Unexpected token import
    at createScript (vm.js:80)
    at Object.runInThisContext (vm.js:139)
    at Module._compile (module.js:606)
    at Object.Module._extensions..js (module.js:653)
    at Module.load (module.js:561)
    at tryModuleLoad (module.js:504)
    at Function.Module._load (module.js:496)
    at Module.require (module.js:586)
    at require (internal/module.js:11)
    at eval (webpack-internal:///clipboardy:1)

package.json

  "dependencies": {
    "ant-design-vue": "^1.7.5",
    "axios": "^0.18.1",
    "clipboard": "^2.0.8",
    "clipboardy": "^3.0.0",
    "electron-store": "^6.0.1",
    "moment": "^2.29.1",
    "v-viewer": "^1.6.3",
    "vditor": "^3.8.7",
    "vue": "^2.5.16",
    "vue-color": "^2.8.1",
    "vue-electron": "^1.0.6",
    "vue-monaco-editor": "^0.0.19",
    "vue-router": "^3.0.1",
    "vuex": "^3.0.1",
    "vuex-electron": "^1.0.0"
  },
  "devDependencies": {
    "@mdi/font": "^5.9.55",
    "ajv": "^6.5.0",
    "babel-core": "^6.26.3",
    "babel-eslint": "^8.2.3",
    "babel-loader": "^7.1.4",
    "babel-minify-webpack-plugin": "^0.3.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-0": "^6.24.1",
    "babel-register": "^6.26.0",
    "cfonts": "^2.1.2",
    "chalk": "^2.4.1",
    "copy-webpack-plugin": "^4.6.0",
    "cross-env": "^5.1.6",
    "css-loader": "^0.28.11",
    "del": "^3.0.0",
    "devtron": "^1.4.0",
    "electron": "^2.0.4",
    "electron-builder": "^19.19.1",
    "electron-debug": "^1.5.0",
    "electron-devtools-installer": "^2.2.4",
    "eslint": "^4.19.1",
    "eslint-config-standard": "^11.0.0",
    "eslint-friendly-formatter": "^4.0.1",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-html": "^4.0.3",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-node": "^6.0.1",
    "eslint-plugin-promise": "^3.8.0",
    "eslint-plugin-standard": "^3.1.0",
    "file-loader": "^1.1.11",
    "html-webpack-plugin": "^3.2.0",
    "listr": "^0.14.3",
    "material-design-icons-iconfont": "^6.1.0",
    "mini-css-extract-plugin": "0.4.0",
    "multispinner": "^0.2.1",
    "node-loader": "^0.6.0",
    "style-loader": "^0.21.0",
    "url-loader": "^1.0.1",
    "vue-devtools": "^5.1.4",
    "vue-html-loader": "^1.2.4",
    "vue-loader": "^15.2.4",
    "vue-style-loader": "^4.1.0",
    "vue-template-compiler": "^2.5.16",
    "webpack": "^4.15.1",
    "webpack-cli": "^3.0.8",
    "webpack-dev-server": "^3.1.4",
    "webpack-hot-middleware": "^2.22.2",
    "webpack-merge": "^4.1.3"
  }

vue file:

import clipboard from 'clipboardy'

methods:{
paste () {
 const txt = clipboard.readSync()
 console.log(txt)
}

Error 1418 always on first try

Thanks for your work!

Unfortunately using the writeSync Method always fails for me on first try with "Error 1418" while retrying it immediately afterwards works....
But before returning the error it waits for 5 Seconds thus resulting in a delay.

Thanks and best regards

Thiemo

Windows clipboard copying doesn't work when using pkg to create a snapshot

I'm on windows 10 and node 8.10.0
Here's the error I am getting when I create a binary snapshot using pkg(https://www.npmjs.com/package/pkg):

{ Error: write EPIPE
at _errnoException (util.js:1024:11)
at Socket._writeGeneric (net.js:767:25)
at Socket._write (net.js:786:8)
at doWrite (_stream_writable.js:387:12)
at writeOrBuffer (_stream_writable.js:373:5)
at Socket.Writable.write (_stream_writable.js:290:11)
at Socket.write (net.js:704:40)
at Socket.Writable.end (_stream_writable.js:553:10)
at Socket.end (net.js:496:31)
at handleInput (C:\snapshot\package_name\node_modules\execa\index.js:75:17)
code: 'EPIPE',
errno: 'EPIPE',
syscall: 'write',
killed: false,
stdout: '',
stderr: '',
failed: true,
signal: null,
cmd: 'C:\snapshot\package_name\node_modules\clipboardy\fallbacks\windows\clipboard_x86_64.exe --copy',
timedOut: false }

I am not sure what is causing this issue, It works otherwise if I run the code as is without creating a snapshot.

Can anyone please help me?

Thank you!


IssueHunt Summary

sindresorhus sindresorhus has been rewarded.

Backers (Total: $40.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

Description

On version 3.0.0 clipboardy crashes with following message:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: c:\Users\...\node_modules\clipboardy\index.js
require() of ES modules is not supported.
require() of c:\Users\...\clip-issue\node_modules\clipboardy\index.js from c:\Users\...\clip-issue\src\main.ts is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from c:\Users\...\clip-issue\node_modules\clipboardy\package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (c:\Users\...\clip-issue\src\main.ts:1:1)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Module.m._compile (C:\Users\...\Roaming\npm\node_modules\ts-node\src\index.ts:1295:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Object.require.extensions.<computed> [as .ts] (C:\Users\...\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1298:12)    

Version 2.3.0 works fine. The code in the linked repo uses regular ts import syntax.

Replicate

Just clone the linked repo, install libs (used yarn) and run the typescript file with ts-node

Link

https://github.com/alexn-s/clipboardy-issue

EOL problem

clip

I'm use this moudle in win10, it work nice,
but when use paste, i get 【\r\r\n】, actually i want 【\r\n】;
it show right in terminal, but in file it will bing too many blank lines.

I have checked #17
I didnot use copy.exe, I copy words manual

"Command failed" on paste

Issuehunt badges

I'm using the Clipboard Ring extension (https://github.com/SrTobi/code-clip-ring) in VS Code, which has a dependency on clipboardy ^1.2.3.

I occasionally get the following error, preventing me from pasting the content of my clipboard:

Command failed: C:\Users\Tim\.vscode\extensions\code-clip-ring\node_modules\clipboardy\fallbacks\windows\clipboard_x86_64.exe --paste thread 'main' panicked at 'Error: Could not paste from clipboard: Error { repr: Os { code: 0, message: "The operation completed successfully." } }', src\libcore\result.rs:906:4 note: Run with RUST_BACKTRACE=1 for a backtrace.

Seems strange that clipboard_x86_64.exe reports an Error with what looks like a success message?

I think restarting VS Code might fix this, but it's a nuisance. Any ideas?

Other info:
I'm running Windows 10 Home N. VS Code: Version 1.24.1.

There is a $60.00 open bounty on this issue. Add more on Issuehunt.

Error on Ubuntu

Hello!
I created VSCode extension with the use of Clipboardy; On windows everything is fine, but when i try to run the command on Ubuntu 18 i got the following error:

Error: Unexpected SIGPIPE
	at process.<anonymous> (/snap/code/35/usr/share/code/resources/app/out/bootstrap.js:5:80)
	at process.emit (events.js:203:13)

This is my extension: link

How can i solve the problem?
Thanks!

Can't Write to Clipboard (Possibly Linux-related)

Issuehunt badges

I've gotten a couple bug reports on my VS Code extension that uses Clipboardy. It seems that there's sometimes a problem calling clipboardy.write(). I haven't been able to reproduce it myself, but both users are running Linux. One in particular is running: Linux x64 4.9.0-8-amd64 (SolydX 9 / Debian Stretch)

One of them gave the following error log...

[Extension Host] Error pasting... TypeError: Cannot read property 'end' of undefined
	at handleInput (/home/sembiance/.vscode/extensions/gazugafan.vscode-indent-on-paste-2.3.2/node_modules/execa/index.js:75:17)
	at module.exports (/home/sembiance/.vscode/extensions/gazugafan.vscode-indent-on-paste-2.3.2/node_modules/execa/index.js:273:2)
	at Object.copy (/home/sembiance/.vscode/extensions/gazugafan.vscode-indent-on-paste-2.3.2/node_modules/clipboardy/lib/linux.js:17:10)
	at Object.exports.write.input [as write] (/home/sembiance/.vscode/extensions/gazugafan.vscode-indent-on-paste-2.3.2/node_modules/clipboardy/index.js:28:20)
	at indentOnPaste (/home/sembiance/.vscode/extensions/gazugafan.vscode-indent-on-paste-2.3.2/out/src/extension.js:96:24)

... the line in my extension triggering this error (out/src/extension.js:96:24) is calling clipboardy.write(). It looks like this...

clipboardy.write(clipboard_1).then(function () {
    ...
}, function () { pasting = false; });

... which seems to be really straightforward to me. Not sure what's going wrong, but according to the error log it could be up in clipboardy or execa. Any ideas? Are there any known issues with clipboardy on certain flavors of Linux?


IssueHunt Summary

stroncium stroncium has been rewarded.

Sponsors (Total: $40.00)

Tips

Loading with --experimental-modules

If I include import clipboard from 'clipboardy' in a script and then run that script with node --experimental-modules script.js, I get Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. This is with Node 12. package.json includes "type": "module"

Couldn't find the `xsel` binary and fallback didn't work.

I run npx semantic-release-cli setup, and I provided these configs

? What is your npm registry? https://registry.npmjs.org/
? What is your npm username? eng.dibo
? What is your npm password? [hidden]
? What is your NPM two-factor authentication code? 060355

but the following error occurred
OS: Debian GNU/Linux 10 (buster)

ERR! semantic-release Error: Couldn't find the `xsel` binary and fallback didn't work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel
ERR! semantic-release     at makeError (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/lib/linux.js:14:11)
ERR! semantic-release     at xselWithFallback (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/lib/linux.js:31:10)
ERR! semantic-release     at processTicksAndRejections (internal/process/task_queues.js:94:5)
ERR! semantic-release  Error: Couldn't find the `xsel` binary and fallback didn't work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel
ERR! semantic-release     at makeError (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/lib/linux.js:14:11)
ERR! semantic-release     at xselWithFallback (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/lib/linux.js:31:10)
ERR! semantic-release     at processTicksAndRejections (internal/process/task_queues.js:94:5) {
ERR! semantic-release   stack: "Error: Couldn't find the `xsel` binary and fallback didn't work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel\n" +
ERR! semantic-release     '    at makeError (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/lib/linux.js:14:11)\n' +
ERR! semantic-release     '    at xselWithFallback (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/lib/linux.js:31:10)\n' +
ERR! semantic-release     '    at processTicksAndRejections (internal/process/task_queues.js:94:5)',
ERR! semantic-release   fallbackError: Error: Command failed: /home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/fallbacks/linux/xsel --clipboard --output
ERR! semantic-release   /home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/fallbacks/linux/xsel: Can't open display: (null)
ERR! semantic-release   : Inappropriate ioctl for device
ERR! semantic-release   
ERR! semantic-release   
ERR! semantic-release       at makeError (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/execa/index.js:174:9)
ERR! semantic-release       at /home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/execa/index.js:278:16
ERR! semantic-release       at processTicksAndRejections (internal/process/task_queues.js:94:5)
ERR! semantic-release       at xselWithFallback (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/lib/linux.js:29:11)
ERR! semantic-release       at Object.default (/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/semantic-release-cli/src/lib/github.js:25:32) {
ERR! semantic-release     code: 1,
ERR! semantic-release     stdout: '',
ERR! semantic-release     stderr: "/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/fallbacks/linux/xsel: Can't open display: (null)\n" +
ERR! semantic-release       ': Inappropriate ioctl for device\n',
ERR! semantic-release     failed: true,
ERR! semantic-release     signal: null,
ERR! semantic-release     cmd: '/home/sh_eldeeb_2010/.npm/_npx/4b6729947d3d91fc/node_modules/clipboardy/fallbacks/linux/xsel --clipboard --output',
ERR! semantic-release     timedOut: false,
ERR! semantic-release     killed: false
ERR! semantic-release   }
ERR! semantic-release }

UTF-8 issues on Windows 10

This is related to #2, I think his fix will most likely work, I also followed this issue on the other popular copy paste library.

Run the following test:

test.only('works with unicode', async t => {
const f = '你好';
t.is(await writeRead(f), f);
});

Now open any other program, notepad etc, and do Edit-Copy or Ctrl+V and you will get 你好.

This is going to be difficult to write a test for since from the libraries standpoint, everything is good. Outside of the library however, it is not actually working with the correct clipboard contents due to encoding.

Error using clipboardy

I have added clipboardy 2.0.0 as a dependency of my node project. in one of my TS scripts I added clipboardy.writeSync(val); and when I start the application I get these errors:
ERROR in ./node_modules/clipboardy/node_modules/cross-spawn/index.js Module not found: Error: Can't resolve 'child_process' in 'C:\repositories\ui\ui\node_modules\clipboardy\node_modules\cross-spawn' ERROR in ./node_modules/clipboardy/node_modules/execa/index.js Module not found: Error: Can't resolve 'child_process' in 'C:\repositories\ui\ui\node_modules\clipboardy\node_modules\execa' ERROR in ./node_modules/clipboardy/node_modules/cross-spawn/lib/util/readShebang.js Module not found: Error: Can't resolve 'fs' in 'C:\repositories\ui\ui\node_modules\clipboardy\node_modules\cross-spawn\lib\util' ERROR in ./node_modules/isexe/index.js Module not found: Error: Can't resolve 'fs' in 'C:\repositories\ui\ui\node_modules\isexe' ERROR in ./node_modules/isexe/windows.js Module not found: Error: Can't resolve 'fs' in 'C:\repositories\ui\ui\node_modules\isexe' ERROR in ./node_modules/isexe/mode.js Module not found: Error: Can't resolve 'fs' in 'C:\repositories\ui\ui\node_modules\isexe' ERROR in ./node_modules/clipboardy/node_modules/get-stream/buffer-stream.js Module not found: Error: Can't resolve 'stream' in 'C:\repositories\ui\ui\node_modules\clipboardy\node_modules\get-stream'

Is there any way to fix this?

Get image from system clipboard

Is there any way to retrieve the image from system clipboard?

It seems the pbpaste not support read the image from clipboard.

Issues with Ubuntu ... ?

When using clipboardy with

 Operating system: _Ubuntu 16.04 LTS_
   VSCode version: _ 1.20.1_
 Markdown+Math version: 2.1.0

by code ...

if (!cb) cb = require('clipboardy');
     cb.write(clipTmpl(mdit.render(doc.getText())))
       .then(()=>vscode.window.showInformationMessage('Html copied to clipboard!'),
             ()=>vscode.window.showInformationMessage('Html copying to clipboard failed!'));

... it says 'Html copying to clipboard failed!', whereas with all other operating systems it seems to work well. See ...

goessner/mdmath#44
goessner/mdmath#36

Is it simply so, that Ubuntu is not supported by clipboardy?

thanks

Can we get complex clipboard data?

Hi @sindresorhus,

are we able to get informations wether the user copied some files from filemanager to clipbard and/or set it vice versa? I m looking for such a functionaltity for an electron driven filemanager application.

Attempting read on Windows 10 throws error due to vbs path issue

Attempting to test the following script on Windows 10:
const clipboardy = require('clipboardy');
console.log('clipboard test: ',clipboardy.readSync());

Causes an error to be thrown on node_modules\execa\index.js:275
throw (result.error || new Error(result.stderr === '' ? result.stdout : result.stderr));
Error: Input Error: Can not find script file "C:\test\clipboard\fallbacks\win-read.vbs".

It looks like part of the path is missing, as the file is really under "C:\test\clipboard\node_modules\clipboardy\fallbacks\win-read.vbs"

Does not work when installed by npm on WSL

Issuehunt badges

In WSL, you can use native windows executables and native linux executables side by side in the same shell. When you install linux node/npm and install clipboardy, it doesn't work as it thinks its on Linux and tries to use xsel, but there is no X server (unless the user installed one).

I had a go at adding support for this in #52 but have closed that as its not a complete solution. WSL support is simple in theory. WSL can run native windows binaries and I can confirm that the fallback executables provided by this module work inside WSL.

The trick is, native windows binaries need to be on a letter drive to run (e.g. C: drive).

This is where things start to get complicated with different paths and environments. WSL has its own filesystem but can also access the standard letter drives under /mnt/c and so on. When clipboardy is installed in WSL, npm installs those .exe files in the fallback directory but these are in a filesystem that is internal to WSL and not accessible to the rest of Windows. Like I said, they need to be on a letter drive where windows can access them.

To make it work when installed in WSL:

  1. clipboard_ARCH.exe needs to be installed somewhere accessible to windows - maybe %APPDATA%/clipboardy/ or something like that

    • how will this be installed?
      a) programmatically
      b) programmatically but with a special command (e.g. npm run install-fallback-exes [LOCATION])
      c) just tell people in the readme: if you want access to windows clipboard in WSL, download these exes, install into your PATH as 'clipboard.exe', then clipboardy will just look for clipboard.exe if its available when on WSL
    • if we are going to install programmatically, some tricks are needed to convert this path to something WSL understands (i.e. '/mnt/c/Users/USERNAME/AppData/...'). So get process.env['APPDATA'], parse it using require('path').win32 API, change 'C:' to '/mnt/c' or whatever drive letter it is, turn the whole thing into a posix path...
  2. need to tell clipboardy to use lib/windows.js when on WSL (since sys.platform === 'linux' it currently tries to use lib/linux.js)

    • (this is what I implemented in my closed PR and is a simple 1 liner using sindresorhus/is-wsl module)
  3. also need to tell lib/windows.js to look for those executables in the place we installed them earlier, or put that location on the PATH. It will not work if it just tries to run the executables in their current location wherever the node modules were installed.


IssueHunt Summary

g-rath g-rath has been rewarded.

Backers (Total: $36.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Return more than one item?

I know that pbpaste returns the last item copied to clipboard. Is there however a way to return a bigger list of items, say the last 100?

Default LC_TYPE

pbcopy and pbpaste use locale environment variables to determine the encoding to be used for input and output. For example, absent other locale settings, setting the environment variable LANG=en_US.UTF-8 will cause pbcopy and pbpaste to use UTF-8 for input and output. If an encoding cannot be determined from the locale, the standard C encoding will be used. Use of UTF-8 is recommended. Note that by default the Terminal application uses the UTF-8 encoding and automatically sets the appropriate locale environment variable.

microsoft/vscode#26502 (comment)

Should we set UTF-8 as default encoding, if no specified?

Doesn't works when I launch my app to Heroku

This is the error i get :
Couldn't find the xsel binary and fallback didn't work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel

I made a discord bot and am trying to launch it in Heroku but the clipboardy does not seems to function . I used Windows 10,Node 14.18.3 and Clipboardy 2.3.0

Support for images/non text clipboard?

Right now when you read the clipboard, clipboardy errors if the clipboard doesn't have text.

Being able to copy other stuff from the clipboard (like: returning a buffer when the clipboard isn't text) would be an amazing feature to have.

Module not found: Error: Can't resolve 'node:process' in 'node_modules/clipboardy'

Hi I have a app + cypress in a same package, I have installed clipboardy on my dev dependency to support cypress test cases, but with the recent 3.0.0 ESM migration, I am unable to run the Cypress because clipboardy throws the following error on runtime

Error: Webpack Compilation Error
./node_modules/clipboardy/index.js
Module not found: Error: Can't resolve 'node:process' in '/Users/myuser/works/myproject/myproject-app/node_modules/clipboardy'
resolve 'node:process' in '/Users/myuser/works/myproject/myproject-app/node_modules/clipboardy'
  Parsed request is a module
  using description file: /Users/myuser/works/myproject/myproject-app/node_modules/clipboardy/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[/Users/myuser/works/myproject/myproject-app/node_modules/node_modules]
[/Users/myuser/works/myproject/node_modules]
[/Users/myuser/works/node_modules]
[/Users/myuser/node_modules]
[/Users/node_modules]
[/node_modules]
[/Users/myuser/works/myproject/myproject-app/node_modules/clipboardy/node_modules/node:process]
[/Users/myuser/works/myproject/myproject-app/node_modules/node:process]
[/Users/myuser/works/myproject/myproject-app/node_modules/clipboardy/node_modules/node:process.js]
[/Users/myuser/works/myproject/myproject-app/node_modules/node:process.js]
[/Users/myuser/works/myproject/myproject-app/node_modules/clipboardy/node_modules/node:process.json]
[/Users/myuser/works/myproject/myproject-app/node_modules/node:process.json]
[/Users/myuser/works/myproject/myproject-app/node_modules/clipboardy/node_modules/node:process.jsx]
[/Users/myuser/works/myproject/myproject-app/node_modules/node:process.jsx]
[/Users/myuser/works/myproject/myproject-app/node_modules/clipboardy/node_modules/node:process.mjs]
[/Users/myuser/works/myproject/myproject-app/node_modules/node:process.mjs]
[/Users/myuser/works/myproject/myproject-app/node_modules/clipboardy/node_modules/node:process.coffee]
[/Users/myuser/works/myproject/myproject-app/node_modules/node:process.coffee]
 @ ./node_modules/clipboardy/index.js 1:0-35 9:9-16 15:7-14
 @ ./cypress/support/commands.js
 @ ./cypress/support/index.js
 
    at Watching.handle [as handler] (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:176:23)
    at /Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/webpack/lib/Watching.js:99:9
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._done (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/webpack/lib/Watching.js:98:28)
    at /Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/webpack/lib/Watching.js:73:19
    at Compiler.emitRecords (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/webpack/lib/Compiler.js:499:39)
    at /Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/webpack/lib/Watching.js:54:20
    at /Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/webpack/lib/Compiler.js:485:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/tapable/lib/Hook.js:154:20)
    at /Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/webpack/lib/Compiler.js:482:27
    at /Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/neo-async/async.js:2818:7
    at done (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/neo-async/async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/myuser/Library/Caches/Cypress/8.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/tapable/lib/Hook.js:154:20)

The Cypress works when I revert back Clipboardy to 2.3.0
Is there any way to fix the above issue with the latest version?

Error when installing clipboardy

When giving "npm install --save clipboardy" getting below error,
.
.
.
406 warn optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
407 warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
408 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS: darwin
408 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: any
408 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS: win32
408 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
409 verbose stack Error: ENOENT: no such file or directory, rename 'C:\QFL-Latest\node_modules\clipboardy\node_modules\cross-spawn' -> 'C:\QFL-Latest\node_modules\execa\node_modules\cross-spawn'
409 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\install\action\move.js:86:7
409 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\iferr\index.js:11:16
409 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\utils\rename.js:11:14
409 verbose stack at CB (C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:93:17)
409 verbose stack at FSReqWrap.oncomplete (fs.js:123:15)
409 verbose stack
409 verbose stack Error: ENOENT: no such file or directory, rename 'C:\QFL-Latest\node_modules\clipboardy\node_modules\cross-spawn' -> 'C:\QFL-Latest\node_modules\execa\node_modules\cross-spawn'
409 verbose stack at Error (native)

Does not work with Windows (32-bit)

Cannot use the module in windows 32 bit device.


let clipboardy = require('clipboardy');

//With clipboardy
for (let index = 0; index < 5; index++) {
    let value = 'test' + index;
    clipboardy.writeSync(value);
    console.log(clipboardy.readSync());
} 

Running above code throws following error

$ node clipboardy_test.js
<...\node_modules\execa\index.js:277>
                throw (result.error || new Error(result.stderr === '' ? result.stdout : result.stderr));
                ^

Error: spawnSync <...\node_modules\clipboardy\fallbacks\windows\copy.exe> UNKNOWN
    at exports._errnoException (util.js:1026:11)
    at Object.spawnSync (child_process.js:461:20)
    at Function.module.exports.sync (<...\node_modules\execa\index.js:274:30>)
    at Object.copySync (<...\node_modules\clipboardy\lib\windows.js:12:26>)
    at Object.exports.writeSync.input [as writeSync] (<...\node_modules\clipboardy\index.js:38:13>)
    at Object.<anonymous> (<...\clipboardy_test.js:6:16>)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)

Then on checking the ' clipboardy \ fallbacks \ windows \ copy.exe' it seems that it supports only 64 bit.

clipboardy \ fallbacks \ windows \ copy.exe is not compatible with running Windows version. Check the system information of the computer and check whether the version of x86 (32 bit) or x64 (64 bit) of the program is required before contacting the software publisher.

This is expected or am i missing something.

My environment:
Node : v6.5.0
Clipboardy: v1.1.4
OS: windows 7 - 32bit

Thanks

Android support

Hello,

I am using Nodejs on Termux, a CLI environment for Android.
Currently clipboardy does not work because I don't have xsel. (And I can't build xsel because X11 is not available in Termux.)
However, Termux provides termux-clipboard-get and termux-clipboard-set commands which use Android's clipboard API.

Do you think it would possible to add support for these commands in clipboardy?

Wayland support

Wayland is a new display manager that's about to ship as a default option in the upcoming Red Hat 8, and will be seeing increasing adoption on additional distros as well.

Best resource I've found with resources for talking to the Wayland clipboard is this stackoverflow.

(Alas at the current time Wayland is a pretentious gasbag that declares only input events are supposed to be able to write to the clipboard, but it appears to be up to the compositor/desktop-env to enforce this. Grah.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.