UserScript
Transform editor text with your own scripts, directly inside VS Code.
Chinese documentation: see READEM_CN.md.
UserScript lets you run either:
- an inline JavaScript snippet from settings
- an external command line script (for example Python, Bash, Batch, PowerShell)
The selected text (or the full document when nothing is selected) is sent to your script and replaced by the script output.
Why This Extension
When text manipulation is too specific for built-in commands, UserScript gives you a quick, repeatable workflow without leaving the editor.
Typical use cases:
- normalize log lines or CSV fragments
- clean generated code blocks
- apply custom formatting rules
- convert case, extract parts, or rewrite patterns
Features
- Run inline JavaScript transform logic from VS Code settings
- Run external scripts through stdin and capture stdout
- Works on selection first, then full document if no selection exists
- Optional confirmation dialog before applying changes
- Context menu integration under User Script
- Status bar shortcut to open extension settings
- Log output channel for troubleshooting
Commands
- User Script: Open Settings
- User Script: Run Inline Script
- User Script: Run External Script
How It Works
- Pick input text:
- If text is selected, only the selection is used.
- If no text is selected, the full document is used.
- UserScript runs your configured transform.
- The script result replaces the original input range.
Extension Settings
userscript.inlineScript
Inline JavaScript code inserted into the body of:
function transform(text: string): string { ... }
Example:
const transformed_text = text.toUpperCase();
return transformed_text;
userscript.externalScript
External command to execute.
Input and output contract:
{text} -> stdin -> your script -> stdout -> {transformed text}
Examples:
- python script.py
- cmd /c script.bat
- powershell -File script.ps1
userscript.skipConfirm
Skip confirmation before applying script results.
Show or hide User Script actions in the editor right-click menu.
External Script Example (Python)
Create a file like script.py:
import sys
text = sys.stdin.read()
result = text.upper()
sys.stdout.write(result)
Set userscript.externalScript to:
python script.py
Security Notes
- Inline and external scripts run with your local user permissions.
- Only run scripts you trust.
- Keep userscript.skipConfirm disabled if you want a safety prompt before every run.
Troubleshooting
- Open the Output panel and select UserScript logs.
- Verify your command works in a normal terminal first.
- Ensure your external script writes transformed text to stdout.
- If using paths with spaces, quote paths appropriately for your shell.
Release Notes
0.0.1
- Initial public version
- Inline script transform
- External script transform
- Selection and full-document support
- Context menu integration