Extension Authoring
Standalone Script Snippets
Single-file script actions with header comment metadata for Python, Shell, JavaScript, and AppleScript.
On this page (8 sections)
In addition to .openclipext package directories, OpenClip supports standalone single-file script snippets (.js, .applescript, .sh, .py). Standalone scripts declare action metadata in header comment blocks that are extracted by OpenClipSnippetParser.
Parser Architecture & Design Constraints#
- Text Parser:
OpenClipSnippetParseroperates purely on string content and line scanning. - Non-isolated & Sendable:
OpenClipSnippetParseris non-isolated andSendable, operating cleanly on background queues without main-actor hops during extension directory scanning.
Header Syntax & Format#
Header metadata can be specified using single-line comment prefixes (// or #) or block keys.
Example 1: Standalone JavaScript Snippet (upper.js)#
javascript
// title: Upper Case Transformer
// icon: symbol:textformat.characters
// identifier: com.user.snippet.uppercase
// javascript:
var text = openclip.input.text;
openclip.paste(text.toUpperCase());Example 2: Standalone Shell Script (format-sql.sh)#
bash
#!/bin/bash
# title: Format SQL Query
# icon: symbol:server.rack
# identifier: com.user.snippet.sqlformat
# shell script:
python3 -c "import sqlparse, sys; print(sqlparse.format(sys.stdin.read(), reindent=True))"Example 3: Standalone AppleScript Snippet (create-note.applescript)#
applescript
-- title: New Quick Note
-- icon: symbol:note.text
-- identifier: com.user.snippet.newnote
-- applescript:
tell application "Notes"
make new note at folder "Notes" with data OPENCLIP_TEXT
end tellExample 4: Standalone URL Search Snippet (search-mdn.sh)#
bash
# title: Search MDN
# icon: symbol:doc.text.magnifyingglass
# url: https://developer.mozilla.org/en-US/search?q={query}Header Keys Matrix#
The parser extracts key-value metadata matching the following recognized keys:
Parsing Algorithm Details#
- Header Line Scanning: Scans up to
Constants.maxHeaderLinesToScanlines for header comment prefixes (//,#,//openclip,#openclip). - Key-Value Splitting: Splits line on the first colon (
:). - Multiline Body Mode: When a runtime key (
url,javascript,applescript,shell script) is encountered without inline content, subsequent lines are accumulated as the script body string. Body mode only ends when a#-prefixed recognized header key appears (e.g. a later# Icon:line);//-prefixed lines and everything else stay part of the body — this preserves JS comments and URLs containing#fragments. - Action Instantiation: The parsed tuple
(ExtensionMetadata, ExtensionActionMetadata)is passed toDefaultActionFactoryto instantiate the runtime action.