atotto / clipboard Goto Github PK
View Code? Open in Web Editor NEWclipboard for golang
License: BSD 3-Clause "New" or "Revised" License
clipboard for golang
License: BSD 3-Clause "New" or "Revised" License
All drone.io links on README is broken
support image form clipboard?
Can you give a thought
I'm getting the following error using the following one liner:
clipboard.WriteAll("test")
fatal error: runtime: stack growth during syscall
runtime stack:
runtime.throw(0x4b9ba50)
/Users/jeffrey/.go_root/src/pkg/runtime/panic.c:520 +0x69
runtime.newstack()
/Users/jeffrey/.go_root/src/pkg/runtime/stack.c:739 +0x7e3
runtime.morestack()
/Users/jeffrey/.go_root/src/pkg/runtime/asm_amd64.s:228 +0x61
goroutine 16 [stack growth]:
syscall.Syscall6(0x7, 0x92ff, 0x6d77664, 0x0, 0xc209433680, 0x0, 0x0, 0x408a169, 0x60, 0xc209433680)
/Users/jeffrey/.go_root/src/pkg/syscall/asm_darwin_amd64.s:44 +0x5 fp=0x6d775c8 sp=0x6d775c0
syscall.wait4(0x92ff, 0x6d77664, 0x0, 0xc209433680, 0x409250b, 0x0, 0x0)
/Users/jeffrey/.go_root/src/pkg/syscall/zsyscall_darwin_amd64.go:32 +0x7d fp=0x6d77628 sp=0x6d775c8
syscall.Wait4(0x92ff, 0x6d776ac, 0x0, 0xc209433680, 0x68ad6b8, 0x0, 0x0)
/Users/jeffrey/.go_root/src/pkg/syscall/syscall_bsd.go:129 +0x64 fp=0x6d77670 sp=0x6d77628
os.(*Process).wait(0xc2099913a0, 0x46439e0, 0x0, 0x0)
/Users/jeffrey/.go_root/src/pkg/os/exec_unix.go:22 +0xfe fp=0x6d77718 sp=0x6d77670
os.(*Process).Wait(0xc2099913a0, 0x0, 0x0, 0x0)
/Users/jeffrey/.go_root/src/pkg/os/doc.go:45 +0x39 fp=0x6d77740 sp=0x6d77718
os/exec.(*Cmd).Wait(0xc20920b2c0, 0x0, 0x0)
/Users/jeffrey/.go_root/src/pkg/os/exec/exec.go:357 +0x1db fp=0x6d77818 sp=0x6d77740
github.com/atotto/clipboard.writeAll(0x4744700, 0x4, 0x0, 0x0)
/Users/jeffrey/go/src/github.com/atotto/clipboard/clipboard_darwin.go:51 +0x1aa fp=0x6d778b0 sp=0x6d77818
github.com/atotto/clipboard.WriteAll(0x4744700, 0x4, 0x0, 0x0)
Mac OS X 10.10
go version go1.3 darwin/amd64
I'm using osx 10.9.5, and following snippet gives a strange output:
package main
import (
"fmt";
"github.com/robertknight/clipboard";
"time";
)
func main() {
for {
s, err := clipboard.ReadAll();
if err != nil {
fmt.Printf("%s\n", err);
}
fmt.Printf("%s\n", s);
time.Sleep(1000 * time.Millisecond);
}
}
it prints:
whatever in clipboard
exec: Stdout already set
exec: Stdout already set
...
how can I fix this?
The library truncates clipboard if content is too large.
I've just tested in Windows.
Find example attached (generated with http://www.json-generator.com/).
Now sure if you're aware of https://github.com/cdown/clipnotify
Allows you to event on clipboard changes.
xsel
and xcopy
are both POSIX programs and run perfectly on any Unix system, including OpenBSD, NetBSD and FreeBSD. Not just Linux.
Instead of being Linux-specific, contents of clipboard_linux.go
should be provided by default as a fallback.
A concerned user reported that one of our security tools was scanning for clipboard programs:
694472 newfstatat(AT_FDCWD, "/home/n/.go/bin/xclip", 0xc0001ab968, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/home/n/.go/bin/xclip", 0xc0002fc448, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/home/n/.local/bin/xclip", 0xc0002fc6b8, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/home/n/bin/xclip", 0xc0002fc788, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/home/n/.cargo/bin/xclip", 0xc0002fc858, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/usr/local/bin/xclip", 0xc0002fc928, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/usr/local/sbin/xclip", 0xc0002fc9f8, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/usr/bin/xclip", 0xc0002fcac8, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/usr/sbin/xclip", 0xc0002fcb98, 0) = -1 ENOENT (No such file or directory)
694472 newfstatat(AT_FDCWD, "/home/n/.go/bin/xsel", 0xc0002fcc68, 0) = -1 ENOENT (No such file or directory)
Since our program does nothing with the clipboard, I was concerned that this might be a supply-chain security attack, so we dug into the dependencies and found this library:
$ go mod graph | egrep -i 'clip|chirp'
x.dev/xctl github.com/atotto/[email protected]
github.com/charmbracelet/[email protected] github.com/atotto/[email protected]
On investigation, we saw that the clipboard library causes a filesystem scan to occur on import:
https://github.com/atotto/clipboard/blob/master/clipboard_unix.go#L51-L97
It would be preferable if this filesystem scan was done as needed rather than at import, not only for binary startup performance but because it's less scary for users when they see this in system call traces.
PS - thank you for the fantastic robust library you have put together.
Hi,
How do I copy without CRLF to clipboard? What should I change in the code?
Thanks in advance.
I created an application that reads the content of the clipboard every second to synchronize several clipboards.
After some time running, the application will become unable to read content from the clipboard and will return this error: fork/exec /usr/bin/pbpaste: too many open files
I have tested it both in macOS and Ubuntu (The message in Ubuntu is the same with different executable and takes longer to appear).
Would be great if one can paste by middle clicking.
echo "testing" | gocopy
Works perfectly well, however, it doesn't return data to stdout, which should IMO be the default behavior. If you want to supress output, then pass a flag;
> echo "testing" | gocopy
"testing"
> echo "testing" | gocopy -q
>
Since gocopy
slurps all input, even using tee
as a workaround doesn't work.
> echo "testing" | tee | gocopy
>
I'm not entirely familiar with the Windows API, but from the description of SetClipboardData() it appears that ownership of the memory object allocated in WriteAll() is not transferred to the system if SetClipboardData fails, so it would be up to WriteAll() to free it.
i want to use to get these files
I dont know how to?
I want to get the file, but not the fileName.
and both might be better
Support of files copied from system
Like, copy a few files from windows explorer and it would give you the name of these files
I can probably build the windows version, but no idea for the other platforms
When I repeatedly read the clipboard and then clear the clipboard, the clipping operation fails and the content cannot be read.
I guessed that the problem might be that I used the writeAll
function and passed in an empty string, so I added a new function: clearAll
func clearAll() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := waitOpenClipboard()
if err != nil {
return err
}
r, _, err := emptyClipboard.Call(0)
_, _, _ = closeClipboard.Call()
if r == 0 {
return err
}
return nil
}
i am using it alongside another package for automating browser testing, and it works will in ordinary mode but if i tried to run my tests in headless mode it don't do any pasting
and it's blocking me for using docker for my tests also
The logic of my progrom is read texts from the clipboard and send them to my server
And clipboard.ReadAll()
works fine when I run the .exe in CMD
But when I tried to run it as a service, clipboard.ReadAll()
returns an error like: The operation completed successfully
Are there any solutions for this? Thank you.
Hi! I've used this little lib in one of my projects and it works great! Thanks for creating this :)
But I would like to make a feature request: add support for clearing the clipboard.
For example, in Linux with xsel
you just need to call xsel -c
.
Not sure about Mac/Windows, but hope it's easy to do as well.
My usecase is that I want to copy sensitive information to the clipboard for a short period of time.
I wrote a sample code like below.
package main
import "fmt"
import "github.com/atotto/clipboard"
func main(){
clipboard.WriteAll("hogehoge")
text,err := clipboard.ReadAll()
if err == nil {
fmt.Printf("[%s]\n",text)
}else{
fmt.Println(err)
}
}
Run it on Windows 7
[C:tstClip]
$ go run tstClip.go
[hogeho]
[C:tstClip]
I expected that [hogehoge] is printed.
I found ReadAll() has no problem on the other test.
Did I do something wrong?
(日本語の方がいいでしょうか?)
Hello. Could you please tag releases so that dep
can use that information to make builds more reproducible?
Check https://github.com/golang/dep.
Currently, using your project with godep I get this in the toml file:
[[constraint]]
branch = "master"
name = "github.com/atotto/clipboard"
With a tag, it would constrain the dependency to that tag.
Support JS clipboard, see:
https://github.com/gowebapi/webapi/blob/master/clipboard/clipboard.go
It would be awesome if executing clip.exe
was used as an additional fallback on Linux. That way, in WSL environments where xclip
and xsel
are not installed, text could be copied to the Windows clipboard. Specifically, I'm trying to use gopass
(which uses this library) under WSL.
In cases where someone is running an X server on WSL, the situation gets complicated unfortunately.
Any plan to support it2copy that comes from iTerm2's Shell Integration?
This could be useful for other projects that use this clipboard project such as k9s.
Example use case would be a user is using Mac OSX, trying to copy k9s outputs via SSH connection (k9s is installed in remote Linux host).
Ref:
Xclip, xsel won't work properly in native Wayland applications. Could the program prefer https://github.com/bugaevc/wl-clipboard if WAYLAND_DISPLAY
is defined?
Issue being a dysfunctional copy and paste after doing "go get github.com/atotto/clipboard". Command does not exist and does not work.
issuing "cat README.md|gocopy" leads to "gocopy: command not found"
Pointed here by a dev of another project as a possible cause of the issue, to see the issue I had there see the following link:
Bios-Marcel/cordless#313
Will provide more detail if requested.
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.