{"id":29258152,"url":"https://github.com/tobywf/pasteboard","last_synced_at":"2025-07-04T05:12:06.144Z","repository":{"id":50474907,"uuid":"113779759","full_name":"tobywf/pasteboard","owner":"tobywf","description":"UNSUPPORTED Pasteboard - Python interface for NSPasteboard (macOS clipboard)","archived":false,"fork":false,"pushed_at":"2024-09-03T23:20:25.000Z","size":69,"stargazers_count":35,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-22T02:49:57.419Z","etag":null,"topics":["appkit","clipboard","macos","nspasteboard","pasteboard","python3"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pasteboard/","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tobywf.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-10T20:09:06.000Z","updated_at":"2025-03-28T16:08:56.000Z","dependencies_parsed_at":"2024-06-19T19:03:06.654Z","dependency_job_id":"b49e3e3e-105e-43d7-93ca-1655d5386225","html_url":"https://github.com/tobywf/pasteboard","commit_stats":{"total_commits":31,"total_committers":4,"mean_commits":7.75,"dds":0.4193548387096774,"last_synced_commit":"5c985c6fd41e1afc48c3788dd651bc84738c92f9"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/tobywf/pasteboard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobywf%2Fpasteboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobywf%2Fpasteboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobywf%2Fpasteboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobywf%2Fpasteboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tobywf","download_url":"https://codeload.github.com/tobywf/pasteboard/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobywf%2Fpasteboard/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261289604,"owners_count":23136085,"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":["appkit","clipboard","macos","nspasteboard","pasteboard","python3"],"created_at":"2025-07-04T05:12:03.546Z","updated_at":"2025-07-04T05:12:06.134Z","avatar_url":"https://github.com/tobywf.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pasteboard\n\n[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0) [![CI](https://github.com/tobywf/pasteboard/actions/workflows/check.yaml/badge.svg)](https://github.com/tobywf/pasteboard/actions)\n\n[Pasteboard](https://pypi.org/project/pasteboard/) exposes Python bindings for reading and writing macOS' AppKit [NSPasteboard](https://developer.apple.com/documentation/appkit/nspasteboard). This allows retrieving different formats (HTML/RTF fragments, PDF/PNG/TIFF) and efficient polling of the pasteboard.\n\nNow with type hints!\n\n## Installation\n\nPython 3.8+ is required. Obviously, this module will only compile on **macOS**:\n\n```bash\npip install pasteboard\n```\n\n## Usage\n\n### Getting the contents\n\n```pycon\n\u003e\u003e\u003e import pasteboard\n\u003e\u003e\u003e pb = pasteboard.Pasteboard()\n\u003e\u003e\u003e pb.get_contents()\n'pasteboard'\n\u003e\u003e\u003e pb.get_contents(diff=True)\n\u003e\u003e\u003e\n```\n\nUnsurprisingly, `get_contents` gets the contents of the pasteboard. This method\ntakes two optional arguments:\n\n**type** - The format to get. Defaults to `pasteboard.String`, which corresponds\nto [NSPasteboardTypeString](https://developer.apple.com/documentation/appkit/nspasteboardtypestring?language=objc). See the `pasteboard` module members for other\noptions such as HTML fragment, RTF, PDF, PNG, and TIFF. Not all formats of [NSPasteboardType](https://developer.apple.com/documentation/appkit/nspasteboardtype?language=objc) are implemented.\n\n**diff** - Defaults to `False`. When `True`, only get and return the contents if it has changed since the last call. Otherwise, `None` is returned. This can be used to efficiently monitor the pasteboard for changes, which must be done by polling (there is no option to subscribe to changes).\n\n`get_contents` will return the appropriate type, so [str](https://docs.python.org/3/library/stdtypes.html#str) for string types,\nand [bytes](https://docs.python.org/3/library/stdtypes.html#bytes) for binary types. `None` is returned when:\n\n* There is no data of the requested type (e.g. an image was copied but a string was requested)\n* **diff** is `True`, and the contents has not changed since the last call\n* An error occurred\n\n### Setting the contents\n\n```pycon\n\u003e\u003e\u003e import pasteboard\n\u003e\u003e\u003e pb = pasteboard.Pasteboard()\n\u003e\u003e\u003e pb.set_contents('pasteboard')\nTrue\n\u003e\u003e\u003e\n```\n\nAnalogously, `set_contents` sets the contents of the pasteboard. This method\ntakes two arguments:\n\n**data** - [str](https://docs.python.org/3/library/stdtypes.html#str) or [bytes-like object](https://docs.python.org/3/glossary.html#term-bytes-like-object), required. There is no type checking. So if `type` indicates a string type and `data` is bytes-like but not UTF-8 encoded, the behaviour is undefined.\n\n**type** - The format to set. Defaults to `pasteboard.String`, which corresponds to [NSPasteboardTypeString](https://developer.apple.com/documentation/appkit/nspasteboardtypestring?language=objc). See the `pasteboard` module members for other options such as HTML fragment, RTF, PDF, PNG, and TIFF. Not all formats of [NSPasteboardType](https://developer.apple.com/documentation/appkit/nspasteboardtype?language=objc) are implemented.\n\n`set_contents` will return `True` if the pasteboard was successfully set; otherwise, `False`. It may also throw [RuntimeError](https://docs.python.org/3/library/exceptions.html#RuntimeError) if `data` can't be converted to an AppKit type.\n\n### Getting file URLs\n\n```pycon\n\u003e\u003e\u003e import pasteboard\n\u003e\u003e\u003e pb = pasteboard.Pasteboard()\n\u003e\u003e\u003e pb.get_file_urls()\n('/Users/\u003cuser\u003e/Documents/foo.txt', '/Users/\u003cuser\u003e/Documents/bar.txt')\n```\n\n**Warning** This API is new, and may change in future.\n\nReturns a `Tuple` of strings, or `None`. Also supports the **diff** parameter analogue to `get_contents`.\n\n## Development\n\nYou don't need to know this if you're not changing `pasteboard.m` code. There are some integration tests in `tests.py` to check the module works as designed (using [pytest](https://docs.pytest.org/en/latest/) and [hypothesis](https://hypothesis.readthedocs.io/en/latest/)).\n\nThis project uses [pre-commit](https://pre-commit.com/) to run some linting hooks when committing. When you first clone the repo, please run:\n\n```\npre-commit install\n```\n\nYou may also run the hooks at any time:\n\n```\npre-commit run --all-files\n```\n\nTo install development dependencies, use:\n\n```\npython3 -m venv env\nsource env/bin/activate\npip install .[dev]\n```\n\nThis will also install development dependencies (`pytest`). To run the tests:\n\n```\npytest tests.py --verbose\n```\n\n## License\n\nFrom version 0.3.0 and forwards, this library is licensed under the Mozilla Public License Version 2.0. For more information, see `LICENSE`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobywf%2Fpasteboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftobywf%2Fpasteboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobywf%2Fpasteboard/lists"}