Giter Site home page Giter Site logo

janlelis / clipboard Goto Github PK

View Code? Open in Web Editor NEW
368.0 15.0 35.0 238 KB

Ruby access to the clipboard on Windows, Linux, macOS, Java, WSL and more platforms 📋︎

License: MIT License

Ruby 100.00%
ruby clipboard linux cygwin windows macos java wsl osc52 wayland

clipboard's People

Contributors

0xced avatar aaronc81 avatar bk2204 avatar cramt avatar grosser avatar janlelis avatar keyworks avatar mlr avatar momo-lab avatar ntachino avatar orange-kao avatar p3t3ru5 avatar trvsdnn avatar woodruffw avatar zhuravel 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

clipboard's Issues

Not working on wayland

xclip and xsel dont work on wayland, there exists a clip called wl-copy which should do the job

Support Slackadays/clipboard

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.

Permission Problem: `const_get': no such file to load -- clipboard/linux (LoadError)

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.

not working on Ubuntu 10.04

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.

Calling Clipboard.paste may trigger unexpected stderr output when clipboard is empty

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

FFI::NullPointerError on Win10

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?

Not working on WSL on Windows 10

It works find in cmd, but doesn't work in bash

OS version

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

xsel as replacement for xclip ?

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

could not deploy to heroku

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!

Update documentation if other TextFormats are supported

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?

Fails with Ocra

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.

Missing dependency

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.

Cannot copy clipboard in linux 16.4

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

Encoding error with Copy

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.

Not copying to clipboard on Ubuntu 16.04.5 LTS

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?

post install message scrambled in ruby 1.9.3

Fetching: clipboard-0.9.9.gem (100%)
��� info �������������������������������
J-_-L � http://github.com/janlelis/clipboard �
��� usage ������������������������������
� require 'clipboard' �
� Clipboard.copy '42' �
� Clipboard.paste #=> 42 �
����������������������������������������

does not work on servers

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

doesn't work well on unicode

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:inpaste'
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:incopy'
from E:/Programs/spacify.rb:14:in `

'

really stupid fix is at line 54 in windows.rb remove .encode(Encoding.default_external)

Cannot copy 8192 bytes of data with xsel

  • OS: Ubuntu Desktop 18.04 LTS (amd64)
  • xsel version 1.2.0
  • xclip not installed
  • Ruby 2.5.1p57
  • clipboard 1.1.2

Reproduce steps

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
}

Expected result

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

Actual result

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

Additional information

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)

Problem on Mac?

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:inrequire'
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:inrequire'
from (irb):1

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.