{"id":16962728,"url":"https://github.com/sgoudham/myclipboard","last_synced_at":"2025-04-14T12:20:22.381Z","repository":{"id":42439597,"uuid":"389426303","full_name":"sgoudham/MyClipboard","owner":"sgoudham","description":"Utility Library to Access and Manipulate the Default System Clipboard","archived":false,"fork":false,"pushed_at":"2023-01-07T03:45:55.000Z","size":124,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T11:09:16.474Z","etag":null,"topics":["clipboard","clipboard-history","cross-platform","java","macos","unix","windows"],"latest_commit_sha":null,"homepage":"","language":"Java","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/sgoudham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-25T19:31:23.000Z","updated_at":"2022-04-06T04:23:31.000Z","dependencies_parsed_at":"2023-02-06T11:15:59.155Z","dependency_job_id":null,"html_url":"https://github.com/sgoudham/MyClipboard","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgoudham%2FMyClipboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgoudham%2FMyClipboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgoudham%2FMyClipboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgoudham%2FMyClipboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgoudham","download_url":"https://codeload.github.com/sgoudham/MyClipboard/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877968,"owners_count":21176244,"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":["clipboard","clipboard-history","cross-platform","java","macos","unix","windows"],"created_at":"2024-10-13T23:07:42.730Z","updated_at":"2025-04-14T12:20:22.345Z","avatar_url":"https://github.com/sgoudham.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[maven-central]: https://img.shields.io/maven-central/v/me.goudham/MyClipboard.svg?label=Maven%20Central\n[build-status]: https://img.shields.io/github/checks-status/sgoudham/MyClipboard/main\n[codecov]: https://codecov.io/gh/sgoudham/MyClipboard/branch/main/graph/badge.svg?token=F4LKql7rIq\n\n![maven-central]\n![build-status]\n![codecov]\n\n# MyClipboard\nUtility Library to Access and Manipulate the Default System Clipboard\n\n# About\nThe inspiration for this project came from my frustration of macOS not having clipboard history \nbuilt-in unlike Windows. This library will allow you to access the system clipboard and manipulate it. \n\n# Configuration\n\nFollow the steps below for a basic implementation: \n\n```java\npublic class Main {\n    public static void main(String[] args) {\n        // Retrieve an instance of MyClipboard\n        MyClipboard myClipboard = MyClipboard.getSystemClipboard();\n\n        // Start listening for clipboard notifications \n        myClipboard.startListening();\n\n        // Add event listeners for different types of events (Text, Image \u0026 File)\n        myClipboard.addEventListener((TextEvent) (oldContent, newContent) -\u003e {\n            String oldText = oldContent.getText();\n            BufferedImage oldImage = oldContent.getImage();\n            List\u003cFile\u003e oldFiles = oldContent.getFiles();\n            System.out.println(\"Old Text: \" + oldText);\n            System.out.println(\"Old Image: \" + oldImage);\n            System.out.println(\"Old File: \" + oldFiles);\n            System.out.println(\"New String Content: \" + newContent);\n        });\n\n        myClipboard.addEventListener((ImageEvent) (oldContent, newContent) -\u003e {\n            String oldText = oldContent.getText();\n            BufferedImage oldImage = oldContent.getImage();\n            List\u003cFile\u003e oldFiles = oldContent.getFiles();\n            System.out.println(\"Old Text: \" + oldText);\n            System.out.println(\"Old Image: \" + oldImage);\n            System.out.println(\"Old File: \" + oldFiles);\n            System.out.println(\"New Image Content: \" + newContent);\n        });\n\n        myClipboard.addEventListener((FileEvent) (oldContent, newContent) -\u003e {\n            String oldText = oldContent.getText();\n            BufferedImage oldImage = oldContent.getImage();\n            List\u003cFile\u003e oldFiles = oldContent.getFiles();\n            System.out.println(\"Old Text: \" + oldText);\n            System.out.println(\"Old Image: \" + oldImage);\n            System.out.println(\"Old File\" + oldFiles);\n            System.out.println(\"New File Content: \" + newContent);\n        });\n        \n        // Insert into the clipboard\n        myClipboard.insert(\"exampleContent\");\n        \n        // Insert and notify MyClipboard of the new content\n        myClipboard.insertAndNotify(\"exampleContent\");\n\n        // Set monitoring for clipboard types\n        myClipboard.setImageMonitored(true || false);\n        myClipboard.setTextMonitored(true || false);\n        myClipboard.setFileMonitored(true || false);\n        \n        // Toggle monitoring for clipboard types\n        myClipboard.toggleTextMonitored();\n        myClipboard.toggleImagesMonitored();\n        myClipboard.toggleFilesMonitored();\n        \n        // Stop listening for clipboard notifications\n        myClipboard.stopListening();\n    }\n}\n```\n\n\n# Windows / *Unix\nThis approach differs from the macOS section below as Windows/*Unix properly notify the program with global clipboard events.\nThis allows for a more event-driven approach as lostOwnership() is triggered whenever the clipboard has lost ownership - clipboard\nhas new content within it - and the contents can be observed by multiple consumers.\n\n# macOS\nUnlike the aforementioned event-driven approach, macOS unfortunately is not very good at notifying the program if the \nsystem clipboard has changed. To query the system clipboard contents, we need to employ a polling schedule. I have chosen\n**200ms** to ensure that images and large files can be copied over as well as reducing the load on the CPU.\n\n# Installation\n\nLatest Stable Version: ![maven-central]\n\u003cp\u003eBe sure to replace the \u003cstrong\u003eVERSION\u003c/strong\u003e key below with the one of the versions shown above!\u003c/p\u003e\n\n**Maven**\n```xml\n\u003c!-- https://mvnrepository.com/artifact/me.goudham/MyClipboard --\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003eme.goudham\u003c/groupId\u003e\n    \u003cartifactId\u003eMyClipboard\u003c/artifactId\u003e\n    \u003cversion\u003eVERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n**Gradle**\n```gradle\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    // https://mvnrepository.com/artifact/me.goudham/MyClipboard\n    implementation group: 'me.goudham', name: 'MyClipboard', version: 'VERSION'\n}\n```\n\n# License \n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fsgoudham%2FMyClipboard.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsgoudham%2FMyClipboard?ref=badge_large)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgoudham%2Fmyclipboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgoudham%2Fmyclipboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgoudham%2Fmyclipboard/lists"}