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.
Metadata
Release files for smartpaste 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| smartpaste-0.1.2.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| smartpaste-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / smartpaste-0.1.2.tar.gz
| Download URL | smartpaste-0.1.2.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fd24d088d48e91571f11b0a1f9ae5e51327af6fe279bb93ca1f0f92402a7e33
|
|
BLAKE2b-256 checksum How to use checksums |
91e0cd24e8f3f5efacc9c582e0550329e5ee5317310e5cb75163f7d10833da20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Release files / smartpaste-0.1.2-py3-none-any.whl
| Download URL | smartpaste-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
526f407c6027c8f923fe796d3bb6622bbf6d823ee5c7f764fe5b5e154c1749d2
|
|
BLAKE2b-256 checksum How to use checksums |
474ddb47bfbf27c19563e1f9d1de47841be5db74ba6dd22019742c5c18d5a799
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|