Skip to main content

Placeholders

Use dynamic placeholders in your actions for powerful automation.

Available Values

ValueURL / AppleScriptShell Script
Selected text{text}"$ONTEXT_TEXT"
Fresh Cmd+C selection{textWithCopy}"$ONTEXT_TEXT_WITH_COPY"
Clipboard snapshot{clipboard}"$ONTEXT_CLIPBOARD"
Prompt input{prompt}Declaration line plus "$ONTEXT_PROMPT_1"
Paste action{paste}{paste}
Date and time{date}, {time}, {datetime}, {weekday}Same placeholders
Shell actions

In a Shell Script action, selected text, clipboard content, and prompt input must use quoted ONTEXT_* environment variables. Keeping user content out of the command source prevents the shell from interpreting it as code.

AppleScript actions

Keep using the placeholder forms shown in the table. OnText passes user-controlled placeholder values as data at runtime instead of inserting them into AppleScript source.

Text Placeholders

{text} - Selected Text (Fast)

Uses Accessibility API for quick text retrieval.

printf '%s' "$ONTEXT_TEXT"

Best for: Simple text operations, most use cases

{textWithCopy} - Selected Text (Accurate)

Uses Cmd+C simulation to obtain the app's copied text representation. This is often more reliable for line breaks and selections that are not exposed correctly through the Accessibility API.

printf '%s' "$ONTEXT_TEXT_WITH_COPY"

Best for: When copy-based capture produces more accurate text or line breaks

Understanding {text} vs {textWithCopy}

By default, {text} uses the Accessibility API to fetch text—it's fast and doesn't leave a trace in the clipboard. However, it can break line breaks in Chrome/HTML and some other apps.

Key differences:

  • {text} - No clipboard trace, but line breaks may be less accurate in some apps
  • {textWithCopy} - Leaves the copied selection in the clipboard and usually preserves line breaks more reliably

Additionally, {text} behavior depends on whether the app supports the Accessibility API properly. Use {textWithCopy} when copy-based text capture is more reliable. Shell and AppleScript actions receive the resulting text value, not the clipboard's rich-text formatting.

This is a limitation of macOS, not OnText.

Clipboard & Paste

{clipboard} - Clipboard Content

Gets current clipboard without modifying selection.

printf 'Clipboard: %s, Selected: %s' "$ONTEXT_CLIPBOARD" "$ONTEXT_TEXT"

If a clipboard item provides both text and an image or another rich format, OnText uses its text representation. A Shell action that needs ONTEXT_CLIPBOARD stops only when no text representation is available.

{paste} - Paste Action

Simulates Cmd+V to paste clipboard content.

printf '%s' "$ONTEXT_TEXT" | tr 'a-z' 'A-Z' | pbcopy && {paste}

User Input

{prompt} - Interactive Input

Shows a dialog for user input. In Shell actions, put the prompt placeholder on its own declaration line. OnText removes that line before execution and passes the result through ONTEXT_PROMPT_1.

{prompt}
printf 'TODO: %s - Created on {date}' "$ONTEXT_PROMPT_1"

Default values: Add text after a colon to set a default value:

{prompt:User name}
printf 'Name: %s' "$ONTEXT_PROMPT_1"

This will show "User name" as the pre-filled default in the input dialog.

For multiple prompts, declaration order determines the variable number:

{prompt:Enter Name}
{prompt:Enter Email}
printf 'Name: %s, Email: %s' "$ONTEXT_PROMPT_1" "$ONTEXT_PROMPT_2" | pbcopy

Date & Time

{date} - Current Date

Format: YYYY-MM-DD (e.g., 2024-01-15)

printf '%s - Added on {date}' "$ONTEXT_TEXT"

{time} - Current Time

Format: HH:MM:SS (e.g., 14:30:45)

printf '[{time}] %s' "$ONTEXT_TEXT"

{datetime} - Date and Time

Combined date and time.

printf 'Log [{datetime}]: %s' "$ONTEXT_TEXT"

{weekday} - Day of Week

Full weekday name (Monday, Tuesday, etc.)

printf '{weekday} TODO: %s' "$ONTEXT_TEXT"

Examples

Timestamp note:

printf '[{datetime}] %s' "$ONTEXT_TEXT" | pbcopy

Template with prompt:

{prompt:Meeting title}
printf 'Meeting: %s\nDate: {date}\nNotes: %s' "$ONTEXT_PROMPT_1" "$ONTEXT_TEXT"

Transform and replace:

printf '%s' "$ONTEXT_TEXT" | tr 'a-z' 'A-Z' | pbcopy && {paste}