{"id":26927524,"url":"https://github.com/lmmx/cliptargets","last_synced_at":"2025-04-02T04:16:32.599Z","repository":{"id":280422014,"uuid":"941953757","full_name":"lmmx/cliptargets","owner":"lmmx","description":"Enumerate multiple clipboard targets on X11 systems","archived":false,"fork":false,"pushed_at":"2025-03-24T22:06:47.000Z","size":101,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T23:20:02.811Z","etag":null,"topics":["clipboard","x-window-system","x11","xclip"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/cliptargets","language":"Python","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/lmmx.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":"2025-03-03T10:30:57.000Z","updated_at":"2025-03-24T22:06:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"095dbc62-f5b8-4dda-92c3-907033bfefc4","html_url":"https://github.com/lmmx/cliptargets","commit_stats":null,"previous_names":["lmmx/cliptargets"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmmx%2Fcliptargets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmmx%2Fcliptargets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmmx%2Fcliptargets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmmx%2Fcliptargets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmmx","download_url":"https://codeload.github.com/lmmx/cliptargets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246752629,"owners_count":20827987,"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","x-window-system","x11","xclip"],"created_at":"2025-04-02T04:16:32.135Z","updated_at":"2025-04-02T04:16:32.593Z","avatar_url":"https://github.com/lmmx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cliptargets\n\n[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)\n[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev)\n[![PyPI](https://img.shields.io/pypi/v/cliptargets.svg)](https://pypi.org/project/cliptargets/)\n[![Python Version](https://img.shields.io/pypi/pyversions/cliptargets.svg)](https://pypi.org/project/cliptargets/)\n[![License](https://img.shields.io/pypi/l/cliptargets.svg)](https://github.com/lmmx/cliptargets/blob/main/LICENSE)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/lmmx/cliptargets/master.svg)](https://results.pre-commit.ci/latest/github/lmmx/cliptargets/master)\n\n**Enumerate multiple X11 clipboard targets (formats).**\n\nPython package for enumerating and accessing multiple clipboard targets (formats) in X11.\n\n## Background\n\nIn the [X Window System](https://en.wikipedia.org/wiki/X_Window_System), a clipboard can hold data\nin multiple different formats simultaneously—in\n*[superposition](https://en.wikipedia.org/wiki/Quantum_superposition)*. Each format (such as plain\ntext, UTF-8 text, or images) is identified by a *target*, with a label that is sometimes a [MIMEtype](https://en.wikipedia.org/wiki/Media_type).\n\n- The program that owns the clipboard, such as [xclip](https://en.wikipedia.org/wiki/Xclip),\n  announces these available targets to other applications.\n- When another application wants to paste, it requests the clipboard data in a specific target format.\n- The clipboard owner then converts and provides the data in the requested format.\n- Although the clipboard owner stores only one original copy of the data, it can supply this data in\n  various formats, depending on what the requesting application needs.\n\n\u003e See [How It Works](https://github.com/lmmx/cliptargets/blob/master/docs/how-it-works.md) for more details\n\ncliptargets handles encoding (some clipboard targets may be non-UTF8) as either a CLI or Python API for inspecting the clipboard's contents across all available formats.\n\n## Features\n\n- **Comprehensive Target Discovery**: Enumerate all available clipboard targets/formats\n- **Intelligent Encoding Detection**: Automatically detects and properly handles various encodings (UTF-8, UTF-16LE, Latin-1)\n- **Format-Specific Handling**: Special handling for Mozilla-specific formats and other binary formats\n- **Simple CLI**: Command-line interface for quick clipboard inspection\n- **Clean Python API**: Programmatic access to clipboard targets\n- **JSON Output**: Option to export all targets and values as JSON\n- **Zero Dependencies**: Core functionality has no external dependencies (beyond xclip)\n\n## Installation\n\n```bash\npip install cliptargets\n```\n\n### Requirements\n\n- Python 3.10+\n- `xclip`\n\n\u003e Note: The `xclip` command-line tool must be installed on your system separately.\n\u003e - On Debian/Ubuntu: `sudo apt install xclip`\n\u003e - On Fedora/RHEL: `sudo dnf install xclip`\n\u003e - On Arch Linux: `sudo pacman -S xclip`\n\n## Usage\n\n### Command Line\n\n```bash\n# Print all clipboard targets and their values\ncliptargets\n\n# Print as JSON\ncliptargets --json\n```\n\n### Python API\n\n```python\nfrom cliptargets import get_all_targets, get_target_value, get_targets\n\n# Get a list of all available targets\ntargets = get_targets()\nprint(f\"Available targets: {targets}\")\n\n# Get the value of a specific target\nvalue = get_target_value(\"STRING\")\nprint(f\"STRING value: {value}\")\n\n# Get a dictionary of all targets and their values\nall_targets = get_all_targets()\nfor target, value in all_targets.items():\n    print(f\"{target}: {value}\")\n```\n\n### Use in Scripts\n\n```python\nimport cliptargets\nimport json\n\n# Get HTML content from clipboard if available\nhtml_content = cliptargets.get_target_value(\"text/html\")\nif html_content:\n    print(\"HTML content found in clipboard!\")\n    # Process the HTML...\n\n# Check if a URL is in the clipboard\nurl = cliptargets.get_target_value(\"text/x-moz-url-priv\")\nif url:\n    print(f\"URL found: {url}\")\n\n# Export all clipboard data to a JSON file\nall_targets = cliptargets.get_all_targets()\nwith open(\"clipboard_data.json\", \"w\") as f:\n    json.dump(all_targets, f, indent=2)\n```\n\n## Why Use This Library?\n\nX11 clipboard can store data in multiple formats simultaneously, but most tools only access the default text format. This library lets you:\n\n1. **Discover Hidden Data**: Access formats like HTML, URLs, and application-specific data\n2. **Debug Copy/Paste Issues**: Diagnose why copy/paste operations work differently between applications\n3. **Handle Encoding Correctly**: Avoid encoding problems with UTF-16LE and other formats\n4. **Access Raw Data**: Get direct access to clipboard data without application interference\n5. **Build Better Tools**: Create clipboard managers and data transfer tools with access to all formats\n\n## Example Output\n\n### STDOUT\n\n```\nFound 9 clipboard targets:\n\nCOMPOUND_TEXT            : Hello World\nMULTIPLE                 : \u003cnot available\u003e\nSTRING                   : Hello World\nTARGETS                  :\nTIMESTAMP\\nTARGETS\\nMULTIPLE\\nUTF8_STRING\\nCOMPOUND_TEXT\\nTEXT\\nSTRING\\ntext/plain;charset=utf-8\\ntext/plain\\n\nTEXT                     : Hello World\nTIMESTAMP                : 62401715\\n\nUTF8_STRING              : Hello World\ntext/plain               : Hello World\ntext/plain;charset=utf-8 : Hello World\n```\n\n### JSON\n\n```json\n{\n  \"TIMESTAMP\": \"62401715\\n\",\n  \"TARGETS\":\n\"TIMESTAMP\\nTARGETS\\nMULTIPLE\\nUTF8_STRING\\nCOMPOUND_TEXT\\nTEXT\\nSTRING\\ntext/plain;charset=utf-8\\ntext/plain\\n\",\n  \"MULTIPLE\": null,\n  \"UTF8_STRING\": \"Hello World\",\n  \"COMPOUND_TEXT\": \"Hello World\",\n  \"TEXT\": \"Hello World\",\n  \"STRING\": \"Hello World\",\n  \"text/plain;charset=utf-8\": \"Hello World\",\n  \"text/plain\": \"Hello World\"\n}\n```\n\n## Project Structure\n\n- `cliptargets/core.py`: Core functionality for handling clipboard targets and encoding\n- `cliptargets/cli.py`: Command-line interface implementation\n- `cliptargets/__init__.py`: Package exports and version information\n\n## Standard X11 Selection Targets\n\nThe ICCCM (Inter-Client Communication Conventions Manual) defines a comprehensive set of standard selection targets. Below is a table of these targets as defined in the X Consortium standards:\n\n| Target Atom | Type | Data Received |\n|-------------|------|---------------|\n| ADOBE_PORTABLE_DOCUMENT_FORMAT | STRING | PDF content |\n| APPLE_PICT | APPLE_PICT | Apple PICT format image data |\n| BACKGROUND | PIXEL | A list of pixel values |\n| BITMAP | BITMAP | A list of bitmap IDs |\n| CHARACTER_POSITION | SPAN | The start and end of the selection in bytes |\n| CLASS | TEXT | Window class information |\n| CLIENT_WINDOW | WINDOW | Any top-level window owned by the selection owner |\n| COLORMAP | COLORMAP | A list of colormap IDs |\n| COLUMN_NUMBER | SPAN | The start and end column numbers |\n| COMPOUND_TEXT | COMPOUND_TEXT | Compound Text |\n| DELETE | NULL | Special target with side effect (selection deletion) |\n| DRAWABLE | DRAWABLE | A list of drawable IDs |\n| ENCAPSULATED_POSTSCRIPT | STRING | EPS data |\n| ENCAPSULATED_POSTSCRIPT_INTERCHANGE | STRING | EPSI data |\n| FILE_NAME | TEXT | The full path name of a file |\n| FOREGROUND | PIXEL | A list of pixel values |\n| HOST_NAME | TEXT | The hostname of the client machine |\n| INSERT_PROPERTY | NULL | Special target with side effect |\n| INSERT_SELECTION | NULL | Special target with side effect |\n| LENGTH | INTEGER | The number of bytes in the selection |\n| LINE_NUMBER | SPAN | The start and end line numbers |\n| LIST_LENGTH | INTEGER | The number of disjoint parts of the selection |\n| MODULE | TEXT | The name of the selected procedure |\n| MULTIPLE | ATOM_PAIR | For requesting multiple targets in one operation |\n| NAME | TEXT | Window name information |\n| ODIF | TEXT | ISO Office Document Interchange Format |\n| OWNER_OS | TEXT | The operating system of the owner client |\n| PIXMAP | PIXMAP | A list of pixmap IDs |\n| POSTSCRIPT | STRING | PostScript data |\n| PROCEDURE | TEXT | The name of the selected procedure |\n| PROCESS | INTEGER, TEXT | The process ID of the owner |\n| STRING | STRING | ISO Latin-1 (+TAB+NEWLINE) text |\n| TARGETS | ATOM | A list of valid target atoms (required) |\n| TASK | INTEGER, TEXT | The task ID of the owner |\n| TEXT | TEXT | The text in the owner's choice of encoding |\n| TIMESTAMP | INTEGER | The timestamp used to acquire the selection (required) |\n| USER | TEXT | The name of the user running the owner |\n\nThese targets allow for rich data exchange between X11 applications. The most commonly used are STRING, UTF8_STRING, and text/plain, but applications should be prepared to handle any of these targets.\n\nSelection owners are required to support at least TARGETS (which returns the list of supported targets) and TIMESTAMP (which returns the time the selection was acquired).\n\nFor more comprehensive details, see the [X Consortium: _Inter-Client Communication Conventions Manual_](https://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html).\n\n## Contributing\n\nContributions are welcome!\n\n1. **Issues \u0026 Discussions**: Please open a GitHub issue for bugs, feature requests, or questions.\n2. **Pull Requests**: PRs are welcome!\n   - Install the dev dependencies with `pip install -e \".[dev]\"`\n   - Make sure tests pass with `pytest`\n   - Format code with `pre-commit run --all-files`\n\n## License\n\nThis project is licensed under the MIT License. See [LICENSE](LICENSE) for details.\n\n## Credits\n\nThe original inspiration for this tool came from troubleshooting complex clipboard encoding issues with X11 applications. Special thanks to the X.org community and the ICCCM documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmmx%2Fcliptargets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmmx%2Fcliptargets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmmx%2Fcliptargets/lists"}