Reliable cross-platform clipboard pasting for Python.
Project description
SmartPaste
Paste anything, reliably. This Python library uses the system clipboard for cross-platform (Win/Mac/Linux) text input, ensuring emojis and complex characters work correctly. Automatically saves/restores clipboard. Ideal for GUI automation.
Features
- Reliable Pasting: Uses the system clipboard (copy/paste) which is generally the most robust way to handle complex characters, emojis, and different scripts compared to simulated typing.
- Cross-Platform: Automatically detects the OS (Windows, macOS, Linux) and uses the correct paste shortcut (
Ctrl+VorCmd+V). - Clipboard Preservation: Saves the current clipboard content before pasting and restores it afterward, minimizing disruption to the user's workflow.
- Error Handling: Includes basic error handling for clipboard operations.
- Configurable Delay: Allows adding a small delay after pasting to ensure the target application processes the input, especially useful for large text blocks or slower applications.
Installation
pip install smartpaste
Usage
Import the package and call it directly with the text you want to paste:
import smartpaste # Import the package
import time
# Give yourself time to focus the target input field
print("Focus the target input field now. Pasting in 5 seconds...")
time.sleep(5)
text_to_paste = "Hello, world! 👋 This text will be pasted reliably."
try:
# Call the package directly!
smartpaste(text_to_paste)
# You can still optionally provide a delay:
# smartpaste("Some text", delay_after_paste=0.2)
print("Pasting successful!")
except Exception as e:
print(f"An error occurred: {e}")
# The original function is still accessible if needed:
# smartpaste.reliable_paste_text("Original function call")
Important: The script requires a target input field (like a text editor, browser address bar, etc.) to have focus before the paste function is called.
How it Works
The package uses a callable class instance assigned to sys.modules[__name__] in its __init__.py. When you call smartpaste(...), it invokes the __call__ method of this instance, which in turn calls the underlying reliable_paste_text function.
- Save Clipboard: Reads and stores the current clipboard content.
- Copy Target Text: Copies the desired text to the clipboard.
- Paste: Simulates the platform-specific paste keyboard shortcut (e.g.,
Ctrl+VorCmd+V). - Delay (Optional): Pauses briefly to allow the paste action to complete.
- Restore Clipboard: Copies the original content back to the clipboard.
Dependencies
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smartpaste-0.1.2.tar.gz.
File metadata
- Download URL: smartpaste-0.1.2.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fd24d088d48e91571f11b0a1f9ae5e51327af6fe279bb93ca1f0f92402a7e33
|
|
| MD5 |
f8fb6828dc4458d5f64b39dfdcc753f3
|
|
| BLAKE2b-256 |
91e0cd24e8f3f5efacc9c582e0550329e5ee5317310e5cb75163f7d10833da20
|
File details
Details for the file smartpaste-0.1.2-py3-none-any.whl.
File metadata
- Download URL: smartpaste-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
526f407c6027c8f923fe796d3bb6622bbf6d823ee5c7f764fe5b5e154c1749d2
|
|
| MD5 |
410d6c489d40d46e52938a819db1e124
|
|
| BLAKE2b-256 |
474ddb47bfbf27c19563e1f9d1de47841be5db74ba6dd22019742c5c18d5a799
|