janlelis / clipboard Goto Github PK
View Code? Open in Web Editor NEWRuby access to the clipboard on Windows, Linux, macOS, Java, WSL and more platforms 📋︎
License: MIT License
Ruby access to the clipboard on Windows, Linux, macOS, Java, WSL and more platforms 📋︎
License: MIT License
Like 'clip' or something along these lines.
Maybe it should be added in a file which is not required by default.
If you like the idea, I'm happy to make a PR.
xclip and xsel dont work on wayland, there exists a clip called wl-copy
which should do the job
Instead of calling xsel
and pbcopy
for X11 and macOS respectively, you can use Clipboard
to condense all those calls into one call to the CB binary. Additionally, CB's Wayland support would also fix #44 at the same time. You could also add a fallback option that uses a bundled CB binary if Clipboard Ruby can't find one installed on the system.
Edit: This would also enable support for the BSDs as well, since CB works on them.
Double edit: This would also enable support for Linux/BSD where there isn't X11/Wayland because CB doesn't depend on them to exist.
Got an error in loading clipboard-1.0.0 on Ubuntu 11.04.
/var/lib/gems/1.8/gems/clipboard-1.0.0/lib/clipboard.rb:29:in
const_get':
no such file to load -- clipboard/linux (LoadError)`
I found all files except windows.rb in /var/lib/gems/1.8/gems/clipboard-1.0.0/lib/clipboard/ are not permitted to be read by non-owner.
So I executed sudo chmod 0644 /var/lib/gems/1.8/gems/clipboard-1.0.0/lib/clipboard/*
, then it worked correctly.
I made sure got latest xclip & clipboard installed.
I think the problem is in lib/clipboard.rb
unless error.read =~ /\^xclip version/
I tried the following in irb:
>> puts `xclip -version`.include?('xclip version') #=> nil
xclip version 0.12
Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL
false
>> puts `xclip -version` #=> nil
xclip version 0.12
Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL
Maybe because xclip doesn't write on standard IO?
Pardon for my so-so IO foo.
OS: Ubuntu Linux 14.04 LTS
xclip installed
Code
#!/usr/bin/env ruby
# encoding: utf-8
require "clipboard"
data = Clipboard.paste
if data == ""
$stdout.puts "Clipboard is empty"
else
$stdout.puts "Clipboard is not empty"
end
Output (by running above script right after reboot, when the clipboard is empty)
$ ./clipboard-test
Error: target STRING not available
Clipboard is empty
This happened because xclip will generate error message to stderr when clipboard is empty
$ xclip -o -selection clipboard
Error: target STRING not available
It would be pretty cool because then it would automatically do it for people.
however you might need a check for only windows but I'm sure that's possible
Just tried to do this
Clipboard.copy '1111'
and it always fails with an exception:
…/gems/clipboard-1.3.5/lib/clipboard/windows.rb:76:in `put_bytes': invalid memory write at address=0x0000000000000000 (FFI::NullPointerError)
from …/gems/3.0.0/gems/clipboard-1.3.5/lib/clipboard/windows.rb:76:in `copy'
from …/gems/3.0.0/gems/clipboard-1.3.5/lib/clipboard.rb:62:in `copy'
Ruby: ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x64-mingw32]
gems:
fiddle - v1.0.6 (ruby)
clipboard - v1.3.5 (ruby)
open3 - v0.1.1 (ruby)
ffi - v1.15.3 (x64-mingw32)
Is it only for me or there is some problem?
The following script causes FrozenError on Windows at here.
gem "clipboard", "1.3.1"
require "clipboard"
Clipboard.copy "Foo"
The cause is simply adding # frozen_string_literal: true
.
It works find in cmd, but doesn't work in bash
Microsoft Windows 10.0.17134.441
cat /proc/version
// => Linux version 4.4.0-17134-Microsoft ([email protected]) (gcc version 5.4.0 (GCC) ) #345-Microsoft Wed Sep 19 17:47:00 PST 2018
i am using glipper, and when doing xclipboard it warns me that another clipboard is used, but xsel --clipboard just works
another alternative would be to use ruby-gnome2, they also have clipboard access
hi
when i deploy app from my local windows to heroku free server and run--heroku rake db:migrate,
i get error saying something like 'not found program xclip',i have pasted as following:
$ heroku rake db:migrate
(in /disk1/home/slugs/03f792ca-4b64-4418-9e51-b280269f55d2/mnt)
rake aborted!
clipboard -
Could not find required prgram xclip
You can install it (on debian/ubuntu) with sudo apt-get install xclip
/disk1/home/slugs/03f792ca-4b64-4418-9e51-b280269f55d2/mnt/Rakefile:4
(See full trace by running task with --trace)
can you tell us how to deal with xclip related problem? Thanks!
I couldn't make out from the README if clipboard
gem supports getting formatting clipboard contents (RTF, HTML, Files, etc) or only text. Looking into the code it seems not (right?).
Could you update the readme to give this as a limitation?
Ocra always forces the loading of all autoload files, to ensure that they are included in the Windows executable that it creates. Although the way you use autoload is neat, it fails in this specific instance. I suggest checking the Ocra constant (it is defined only if Ocra is building an executable):
unless defined? Ocra autoload :Linux, 'clipboard/linux' autoload :Mac, 'clipboard/mac' end autoload :Windows, 'clipboard/windows' autoload :File, 'clipboard/file'
This patch works for me.
This gem requires ffi to run, and if you don't have it using require 'clipboard' gives you an error and tells you to run gem install ffi.
Hi, I still cannot use clipboard in my ruby script and linux server
xclip -version
xclip version 0.12
Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL
I tried Clipboard.copy("abc") but it does not copy the abc word, I'm using
gem 'clipboard', '~> 1.1', '>= 1.1.1'
any idea what's wrong? thank u
I was playing around with the Clipboard.copy function and tried copying the string some unicode and got this exception
Clipboard.copy("\u00AE") #=> Encoding::UndefinedConversionError: U+00AE to IBM437 in conversion from UTF-16LE to UTF-8 to IBM437
I'm still trying to determine if I can get solve this problem by forcing the encoding prior to copying the text but I figured I'd pass the word on this.
Hi!
I installed this in a Rails 5 app on Ubuntu:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
irb(main):003:0> puts xclip -version
.include?('xclip version')
xclip version 0.12
Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL
false
=> nil
irb(main):004:0> puts xclip -version
xclip version 0.12
Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL
When I run rails console and try to use the Clipboard, no luck:
irb(main):001:0> Clipboard.copy "mac"
=> ""
irb(main):002:0> Clipboard.paste
=> ""
Any ideas?
Fetching: clipboard-0.9.9.gem (100%)
��� info �������������������������������
J-_-L � http://github.com/janlelis/clipboard �
��� usage ������������������������������
� require 'clipboard' �
� Clipboard.copy '42' �
� Clipboard.paste #=> 42 �
����������������������������������������
irb -r clipboard
>> Clipboard.paste
Error: Can't open display: (null)
=> ""
my recommendation would be to detect if any display is running/if its a ssh shell?
and then just use some local file ~/.clipboard ...
best solution would be to get clipboard from connected user, imo thats what the user would expect
...
E:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/clipboard-1.0.6/lib/clipboard/windows.rb:54:in encode': U+FF11 to IBM437 in conversion from UTF-16LE to UTF-8 to IBM437 (Encoding::UndefinedConversionError) from E:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/clipboard-1.0.6/lib/clipboard/windows.rb:54:in
paste'
from E:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/clipboard-1.0.6/lib/clipboard/windows.rb:91:in copy' from E:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/clipboard-1.0.6/lib/clipboard.rb:49:in
copy'
from E:/Programs/spacify.rb:14:in `
really stupid fix is at line 54 in windows.rb remove .encode(Encoding.default_external)
I'm trying to use Clipboard on my automated tests. I'm clicking a button that copies text to clipboard but it's not working when I ran the tests on Browserstack and/or when I ran the tests headless! It keeps getting my system clipboard instead.
Run the following script. This script will generate random data, copy it to the clipboard, and read it back for verification.
#!/usr/bin/env ruby
# encoding: utf-8
require "clipboard"
random = Random.new
Clipboard.clear()
(0..18).each{|power|
data1 = random.bytes(2**power).unpack("H*").first
$stdout.puts "Testing #{data1.bytesize} bytes"
Clipboard.copy(data1)
data2 = Clipboard.paste
if data1 != data2
$stdout.puts "Test failed"
$stdout.puts "Copy: #{data1.bytesize} bytes"
$stdout.puts "Paste: #{data2.bytesize} bytes"
exit 1
end
}
Testing 2 bytes
Testing 4 bytes
Testing 8 bytes
Testing 16 bytes
Testing 32 bytes
Testing 64 bytes
Testing 128 bytes
Testing 256 bytes
Testing 512 bytes
Testing 1024 bytes
Testing 2048 bytes
Testing 4096 bytes
Testing 8192 bytes
Testing 16384 bytes
Testing 32768 bytes
Testing 65536 bytes
Testing 131072 bytes
Testing 262144 bytes
Testing 524288 bytes
Testing 2 bytes
Testing 4 bytes
Testing 8 bytes
Testing 16 bytes
Testing 32 bytes
Testing 64 bytes
Testing 128 bytes
Testing 256 bytes
Testing 512 bytes
Testing 1024 bytes
Testing 2048 bytes
Testing 4096 bytes
Testing 8192 bytes
Test failed
Copy: 8192 bytes
Paste: 4096 bytes
Platform with xclip installed will not be affected by this issue. However, it seems that xclip cannot copy more than 1 MiB of data (1048576 bytes)
20:46:38 ~ gem install clipboard
Successfully installed zucker-6
Successfully installed clipboard-0.8.1
2 gems installed
Installing RDoc documentation for zucker-6...
Installing RDoc documentation for clipboard-0.8.1...
20:47:19 ~ irb -rubygems
ruby-1.8.7-p302 > require 'clipboard'
LoadError: no such file to load -- Win32API
from /Users/murphy/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Users/murphy/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
require'
from /Users/murphy/.rvm/gems/ruby-1.8.7-p302/gems/clipboard-0.8.1/lib/clipboard.rb:11
from /Users/murphy/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require' from /Users/murphy/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
require'
from (irb):1
Clipboard.paste().should == Clipboard.paste('clipboard')
so it behaves consistent on all platforms
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.