Skip to main content

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+V or Cmd+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.

  1. Save Clipboard: Reads and stores the current clipboard content.
  2. Copy Target Text: Copies the desired text to the clipboard.
  3. Paste: Simulates the platform-specific paste keyboard shortcut (e.g., Ctrl+V or Cmd+V).
  4. Delay (Optional): Pauses briefly to allow the paste action to complete.
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartpaste-0.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartpaste-0.1.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

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

Hashes for smartpaste-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2fd24d088d48e91571f11b0a1f9ae5e51327af6fe279bb93ca1f0f92402a7e33
MD5 f8fb6828dc4458d5f64b39dfdcc753f3
BLAKE2b-256 91e0cd24e8f3f5efacc9c582e0550329e5ee5317310e5cb75163f7d10833da20

See more details on using hashes here.

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

Hashes for smartpaste-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 526f407c6027c8f923fe796d3bb6622bbf6d823ee5c7f764fe5b5e154c1749d2
MD5 410d6c489d40d46e52938a819db1e124
BLAKE2b-256 474ddb47bfbf27c19563e1f9d1de47841be5db74ba6dd22019742c5c18d5a799

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page