# Advanced Paste – Python Scripts Advanced Paste supports user-defined Python scripts that transform clipboard content. Scripts are discovered automatically from a configurable folder and appear as actions in the Advanced Paste UI. ## Quick start 1. Open the scripts folder — by default `%LOCALAPPDATA%\Microsoft\PowerToys\AdvancedPaste\Scripts`. You can change this in **Settings → Advanced Paste → Python scripts → Scripts folder**. 2. Drop a `.py` file into the folder. 3. Add the required header comments at the top (see [Header format](#header-format)). 4. Open the Advanced Paste UI (`Win+Shift+V`) — your script will appear in the action list. ## Header format Every script must start with one or more **header comment lines**. Each line follows the pattern: ``` # @advancedpaste: ``` The parser reads the first 50 lines of each file; only lines beginning with `#` are inspected. ### Supported tags | Tag | Required | Description | |-----|----------|-------------| | `name` | **Yes** | Display name shown in the Advanced Paste UI. | | `desc` | No | Short description / tooltip. | | `formats` | No | Comma-separated list of supported clipboard formats. Defaults to **all** formats when omitted. | | `platform` | No | `windows` (default) or `linux`. Determines the execution mode (see below). | | `version` | No | Free-form version string (reserved for future use). | | `requires` | No | Space-separated Python package requirements. See [Declaring dependencies](#declaring-dependencies). | ### Formats | Value | Clipboard content | |-------|--------------------| | `text` | Plain or Unicode text (`CF_UNICODETEXT`) | | `html` | HTML fragment (`CF_HTML`) | | `image` | Bitmap / PNG image | | `audio` | Audio file(s) | | `video` | Video file(s) | | `files` or `file` | File paths (`CF_HDROP` / `StorageItems`) | | `any` | All of the above | Multiple values can be combined with commas: ```python # @advancedpaste:formats text,html ``` ## Execution modes ### Windows mode (`platform windows`) The script runs directly on Windows via the configured Python interpreter. It **owns the clipboard** — use a library like `pywin32` (`win32clipboard`) to read and write clipboard data. **Invocation:** ``` python.exe "" --format --work-dir "" ``` **Minimal example — reverse text:** ```python # @advancedpaste:name Reverse text # @advancedpaste:formats text # @advancedpaste:platform windows import win32clipboard win32clipboard.OpenClipboard() text = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT) win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, text[::-1]) win32clipboard.CloseClipboard() ``` After the script exits with code 0, Advanced Paste re-reads the clipboard and pastes the result. A non-zero exit code signals failure; stderr is shown in the error UI. ### WSL / Linux mode (`platform linux`) The script runs inside WSL via `wsl.exe bash -l -c "python3 -X utf8