{"id":13414107,"url":"https://github.com/golang-design/clipboard","last_synced_at":"2025-04-12T23:43:03.153Z","repository":{"id":37048426,"uuid":"314230339","full_name":"golang-design/clipboard","owner":"golang-design","description":"📋 cross-platform clipboard package that supports accessing text and image in Go (macOS/Linux/Windows/Android/iOS) ","archived":false,"fork":false,"pushed_at":"2024-08-20T08:34:57.000Z","size":844,"stargazers_count":667,"open_issues_count":28,"forks_count":68,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-12T23:42:58.460Z","etag":null,"topics":["android","clipboard","clipboard-library","cross-platform","go","golang","ios","linux","macos","nspasteboard","windows","x11"],"latest_commit_sha":null,"homepage":"https://golang.design/x/clipboard","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/golang-design.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["changkun"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-11-19T11:42:08.000Z","updated_at":"2025-04-11T17:59:18.000Z","dependencies_parsed_at":"2024-06-18T12:35:56.228Z","dependency_job_id":"d2598bcb-4441-4a51-af90-f9129c2ed8ad","html_url":"https://github.com/golang-design/clipboard","commit_stats":{"total_commits":51,"total_committers":12,"mean_commits":4.25,"dds":0.2941176470588235,"last_synced_commit":"b50badc062a526673961e1465a673e3f3dfc1464"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-design%2Fclipboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-design%2Fclipboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-design%2Fclipboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-design%2Fclipboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/golang-design","download_url":"https://codeload.github.com/golang-design/clipboard/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647256,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","clipboard","clipboard-library","cross-platform","go","golang","ios","linux","macos","nspasteboard","windows","x11"],"created_at":"2024-07-30T20:01:57.880Z","updated_at":"2025-04-12T23:43:03.129Z","avatar_url":"https://github.com/golang-design.png","language":"Go","funding_links":["https://github.com/sponsors/changkun"],"categories":["开源类库","Utilities","Go","语言资源库","常用工具","公用事业公司","Utility"],"sub_categories":["未归类","Utility/Miscellaneous","go","爬虫工具","实用程序/Miscellaneous","Fail injection","HTTP Clients"],"readme":"# clipboard [![PkgGoDev](https://pkg.go.dev/badge/golang.design/x/clipboard)](https://pkg.go.dev/golang.design/x/clipboard) ![](https://changkun.de/urlstat?mode=github\u0026repo=golang-design/clipboard) ![clipboard](https://github.com/golang-design/clipboard/workflows/clipboard/badge.svg?branch=main)\n\nCross platform (macOS/Linux/Windows/Android/iOS) clipboard package in Go\n\n```go\nimport \"golang.design/x/clipboard\"\n```\n\n## Features\n\n- Cross platform supports: **macOS, Linux (X11), Windows, iOS, and Android**\n- Copy/paste UTF-8 text\n- Copy/paste PNG encoded images (Desktop-only)\n- Command `gclip` as a demo application\n- Mobile app `gclip-gui` as a demo application\n\n## API Usage\n\nPackage clipboard provides cross platform clipboard access and supports\nmacOS/Linux/Windows/Android/iOS platform. Before interacting with the\nclipboard, one must call Init to assert if it is possible to use this\npackage:\n\n```go\n// Init returns an error if the package is not ready for use.\nerr := clipboard.Init()\nif err != nil {\n      panic(err)\n}\n```\n\nThe most common operations are `Read` and `Write`. To use them:\n\n```go\n// write/read text format data of the clipboard, and\n// the byte buffer regarding the text are UTF8 encoded.\nclipboard.Write(clipboard.FmtText, []byte(\"text data\"))\nclipboard.Read(clipboard.FmtText)\n\n// write/read image format data of the clipboard, and\n// the byte buffer regarding the image are PNG encoded.\nclipboard.Write(clipboard.FmtImage, []byte(\"image data\"))\nclipboard.Read(clipboard.FmtImage)\n```\n\nNote that read/write regarding image format assumes that the bytes are\nPNG encoded since it serves the alpha blending purpose that might be\nused in other graphical software.\n\nIn addition, `clipboard.Write` returns a channel that can receive an\nempty struct as a signal, which indicates the corresponding write call\nto the clipboard is outdated, meaning the clipboard has been overwritten\nby others and the previously written data is lost. For instance:\n\n```go\nchanged := clipboard.Write(clipboard.FmtText, []byte(\"text data\"))\n\nselect {\ncase \u003c-changed:\n      println(`\"text data\" is no longer available from clipboard.`)\n}\n```\n\nYou can ignore the returning channel if you don't need this type of\nnotification. Furthermore, when you need more than just knowing whether\nclipboard data is changed, use the watcher API:\n\n```go\nch := clipboard.Watch(context.TODO(), clipboard.FmtText)\nfor data := range ch {\n      // print out clipboard data whenever it is changed\n      println(string(data))\n}\n```\n\n## Demos\n\n- A command line tool `gclip` for command line clipboard accesses, see document [here](./cmd/gclip/README.md).\n- A GUI application `gclip-gui` for functionality verifications on mobile systems, see a document [here](./cmd/gclip-gui/README.md).\n\n\n## Command Usage\n\n`gclip` command offers the ability to interact with the system clipboard\nfrom the shell. To install:\n\n```bash\n$ go install golang.design/x/clipboard/cmd/gclip@latest\n```\n\n```bash\n$ gclip\ngclip is a command that provides clipboard interaction.\n\nusage: gclip [-copy|-paste] [-f \u003cfile\u003e]\n\noptions:\n  -copy\n        copy data to clipboard\n  -f string\n        source or destination to a given file path\n  -paste\n        paste data from clipboard\n\nexamples:\ngclip -paste                    paste from clipboard and prints the content\ngclip -paste -f x.txt           paste from clipboard and save as text to x.txt\ngclip -paste -f x.png           paste from clipboard and save as image to x.png\n\ncat x.txt | gclip -copy         copy content from x.txt to clipboard\ngclip -copy -f x.txt            copy content from x.txt to clipboard\ngclip -copy -f x.png            copy x.png as image data to clipboard\n```\n\nIf `-copy` is used, the command will exit when the data is no longer\navailable from the clipboard. You can always send the command to the\nbackground using a shell `\u0026` operator, for example:\n\n```bash\n$ cat x.txt | gclip -copy \u0026\n```\n\n## Platform Specific Details\n\nThis package spent efforts to provide cross platform abstraction regarding\naccessing system clipboards, but here are a few details you might need to know.\n\n### Dependency\n\n- macOS: require Cgo, no dependency\n- Linux: require X11 dev package. For instance, install `libx11-dev` or `xorg-dev` or `libX11-devel` to access X window system.\n- Windows: no Cgo, no dependency\n- iOS/Android: collaborate with [`gomobile`](https://golang.org/x/mobile)\n\n### Screenshot\n\nIn general, when you need test your implementation regarding images,\nThere are system level shortcuts to put screenshot image into your system clipboard:\n\n- On macOS, use `Ctrl+Shift+Cmd+4`\n- On Linux/Ubuntu, use `Ctrl+Shift+PrintScreen`\n- On Windows, use `Shift+Win+s`\n\nAs described in the API documentation, the package supports read/write\nUTF8 encoded plain text or PNG encoded image data. Thus,\nthe other types of data are not supported yet, i.e. undefined behavior.\n\n## Who is using this package?\n\nThe main purpose of building this package is to support the\n[midgard](https://changkun.de/s/midgard) project, which offers\nclipboard-based features like universal clipboard service that syncs\nclipboard content across multiple systems, allocating public accessible\nfor clipboard content, etc.\n\nTo know more projects, check our [wiki](https://github.com/golang-design/clipboard/wiki) page.\n\n## License\n\nMIT | \u0026copy; 2021 The golang.design Initiative Authors, written by [Changkun Ou](https://changkun.de).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolang-design%2Fclipboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgolang-design%2Fclipboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolang-design%2Fclipboard/lists"}