> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cyberdesk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Copy to Clipboard

> Deterministic data extraction via clipboard as an alternative to vision-based extraction

## What is Copy to Clipboard?

Copy to Clipboard is a deterministic extraction tool that executes `Ctrl+C` on the remote machine, captures the clipboard contents, and automatically saves the result as a runtime variable. It provides a fast, reliable alternative to vision-based extraction methods.

<Note>
  In your prompts, always refer to this tool as `copy_to_clipboard` (lowercase, with underscores).
</Note>

## Why This Tool Exists

Cyberdesk offers two primary methods for extracting data from screens:

**Vision-Based Extraction** ([`focused_action`](/workflow-prompting/focused-action), [`extract_prompt`](/workflow-prompting/extract-prompt))

* Uses AI to read and interpret screenshots
* Best for: Complex layouts, tables, ambiguous text, visual verification
* Trade-offs: Requires AI inference, slightly slower, interpretation-based

**Clipboard-Based Extraction** (`copy_to_clipboard`)

* Deterministic copy via `Ctrl+C`, captures exact clipboard text
* Best for: Selectable/copyable fields—IDs, numbers, dates, text inputs
* Trade-offs: **Only works if text is copyable**, requires explicit selection

The `copy_to_clipboard` tool is ideal when you want fast, deterministic extraction without vision model inference—but **only works when text is selectable**. Use vision-based extraction when text is embedded in images, PDFs, charts, or other non-copyable formats.

## How It Works

1. Agent selects the text/data on screen (e.g., triple-click, drag selection, or keyboard shortcuts)
2. Agent calls `copy_to_clipboard` with a runtime variable key name
3. System executes `Ctrl+C` on the remote machine
4. Clipboard contents are captured and returned to the agent
5. Data is **automatically saved as a runtime variable**: `{{key_name}}`
6. The captured value can be used in subsequent workflow steps
7. At run completion, runtime values are included when generating final `output_data` JSON

<Info>
  The clipboard data is automatically saved as a **runtime variable**, making it immediately available for:

  * Use in later workflow steps via `{{variable_name}}` syntax
  * **Automatic inclusion in the final workflow output** when you have an output schema defined

  This means you don't need to manually include clipboard values in your output—they're captured automatically alongside focused action observations when transforming to the final output JSON.
</Info>

## Choosing Between Vision and Clipboard Extraction

Both extraction methods are valid—choose based on your use case:

### Use Copy to Clipboard When:

* **The text is selectable and copyable** (works with Ctrl+C)
* You know exactly which field to select
* You want deterministic, byte-for-byte accuracy
* The field has consistent location/structure
* Speed is critical (no AI inference needed)
* You're extracting simple IDs, numbers, or short text

### Use Vision-Based Extraction When:

* **The text cannot be copied** (rendered in images, PDFs, scanned documents, charts)
* **The text is not selectable** (displayed as graphics, embedded in screenshots)
* Layout is complex or changes between runs
* Data is in tables or complex formats
* You need to verify visual states or conditions
* Text location is unpredictable
* You need decision-making alongside extraction

<Tip>
  **Pro Tip**: For workflows with output schemas, `copy_to_clipboard` is often faster and more reliable for extracting known fields like IDs, dates, or account numbers. The captured values automatically flow into your final output data.
</Tip>

## When to Use Copy to Clipboard

### 1. Extracting Non-Selectable IDs

```text theme={null}
"Triple-click on the account number field to select it, then use copy_to_clipboard 
with key name 'account_number' to capture and save the value as {{account_number}}"
```

### 2. Capturing Protected Text

```text theme={null}
"Right-click on the customer ID, select 'Copy' from the context menu, then use 
copy_to_clipboard with key name 'customer_id' to save the value"
```

### 3. Getting Values from Legacy Systems

```text theme={null}
"In the patient record screen, click into the MRN field and press Ctrl+A to select all. 
Then use copy_to_clipboard with key name 'patient_mrn' to capture the medical 
record number as {{patient_mrn}}"
```

### 4. Extracting Data for Later Use

```text theme={null}
"Navigate to the invoice details page and copy the invoice number. Use 
copy_to_clipboard with key name 'invoice_id' to save it. Later, type this value 
into the payment field using {{invoice_id}}"
```

### 5. When Vision is Required (Non-Copyable Text)

```text theme={null}
"On the dashboard, you'll see a revenue chart with the total displayed inside 
the graph. Since this is a chart image and the number isn't copyable text, 
use focused_action to read the revenue total from the chart and save it as 
{{revenue_total}}"
```

<Info>
  Vision-based extraction is **essential** when working with scanned documents, image-based UIs, charts, graphs, or any content where the text isn't selectable. If you try `copy_to_clipboard` on non-copyable content, it will capture whatever was previously on the clipboard (likely empty or wrong).
</Info>

## How to Prompt for Copy to Clipboard

### Best Practices

1. **First Select the Text**: Describe how to select the data (triple-click, drag, Ctrl+A, etc.)
2. **Specify the Key Name**: Choose a clear, descriptive name for the runtime variable
3. **Use the Value Later**: Reference the variable as `{{key_name}}` in subsequent steps
4. **Be Specific**: Indicate exactly what text should be selected and copied

### Prompt Template

```text theme={null}
"[Describe how to select the data], then use copy_to_clipboard with key name 
'[variable_name]' to save it as {{[variable_name]}}"
```

## Real-World Examples

### Healthcare: Extracting Patient MRN

```text theme={null}
"On the patient demographics screen, locate the Medical Record Number field. 
Triple-click on the MRN to select it, then use copy_to_clipboard with key name 
'patient_mrn' to capture the value. Use this {{patient_mrn}} later when filling 
out the lab requisition form."
```

### Finance: Capturing Account Numbers

```text theme={null}
"Navigate to the account summary page. Click into the account number field 
and press Ctrl+A to select all. Use copy_to_clipboard with key name 'account_num' 
to save it as {{account_num}}. Later, you'll need to paste this into the 
transfer form using {{account_num}}"
```

### Insurance: Extracting Claim IDs

```text theme={null}
"After submitting the claim, the system displays a claim ID. Select this ID 
by triple-clicking on it, then use copy_to_clipboard with key name 'claim_id' 
to capture it. Include {{claim_id}} in the workflow output data."
```

### Legal: Copying Case References

```text theme={null}
"In the case management system, locate the case reference number in the header. 
Right-click and select 'Copy Reference', then use copy_to_clipboard with key 
name 'case_ref' to save it as {{case_ref}} for use in document filing."
```

## Working with Runtime Variables

### Setting the Variable

```text theme={null}
"Copy the generated report ID using copy_to_clipboard with key name 'report_id' 
to save it as {{report_id}}"
```

### Using the Variable

```text theme={null}
"Later in the workflow, navigate to the report lookup page and type {{report_id}} 
into the search field to retrieve the report"
```

### Multiple Clipboard Operations

```text theme={null}
"Extract the customer name by selecting it and using copy_to_clipboard with 
key name 'customer_name'. Then navigate to the order ID field, select it, 
and use copy_to_clipboard with key name 'order_id'. Finally, submit a form 
with both {{customer_name}} and {{order_id}}"
```

## Common Selection Patterns

### Triple-Click Selection

```text theme={null}
"Triple-click on the text field to select all contents, then use copy_to_clipboard 
with key name 'field_value'"
```

### Ctrl+A Selection

```text theme={null}
"Click into the input field, press Ctrl+A to select all, then use copy_to_clipboard 
with key name 'full_text'"
```

### Drag Selection

```text theme={null}
"Click and drag to select the account number from the table cell, then use 
copy_to_clipboard with key name 'account_number'"
```

### Context Menu Copy

```text theme={null}
"Right-click on the value and select 'Copy' from the menu, then immediately use 
copy_to_clipboard with key name 'copied_value' to capture what was copied"
```

## Integration with Other Tools

### With Focused Action

```text theme={null}
"Use focused_action to locate the row matching {customer_name} in the table. 
Once found, copy the order ID from that row using copy_to_clipboard with key 
name 'order_id', then use {{order_id}} to look up the order details."
```

### With Terminal Commands

```text theme={null}
"After copying the file path with copy_to_clipboard and saving it as {{file_path}}, 
use execute_terminal_command to run 'Get-Item {{file_path}} | ConvertTo-Json' 
to get file metadata"
```

### With Workflow Output Schema

```text theme={null}
"Define your workflow output schema as:
{
  'customer_id': 'string',
  'order_number': 'string', 
  'order_date': 'string',
  'total_amount': 'string'
}

During the workflow:
- Triple-click the Customer ID field and use copy_to_clipboard with key name 'customer_id'
- Triple-click the Order Number and use copy_to_clipboard with key name 'order_number'
- Use focused_action to extract the order date and save as {{order_date}}
- Triple-click the Total Amount and use copy_to_clipboard with key name 'total_amount'

The runtime variables will automatically be included when generating the final output_data JSON."
```

<Info>
  **Automatic Output Generation**: When you define an output schema, Cyberdesk automatically transforms runtime values (from `copy_to_clipboard`) and focused action observations into the final structured output. You don't need to manually construct the output JSON—just extract the values and they'll be included automatically.
</Info>

## Error Prevention

<Warning>
  **Common mistakes to avoid:**

  1. Calling `copy_to_clipboard` without first selecting the text
  2. Using the same key name multiple times (will overwrite previous values)
  3. Forgetting to select text before copying
  4. Not accounting for empty clipboard (if Ctrl+C fails)
</Warning>

### ❌ Incorrect Usage

```text theme={null}
"Use copy_to_clipboard to get the account number"              // Didn't select first
"Copy the value as 'value'"                                    // Not clear which value
"Use copy to save it"                                          // Wrong tool name
```

### ✅ Correct Usage

```text theme={null}
"Triple-click the account number field, then use copy_to_clipboard with key name 'account_number'"
"Select the text by clicking and dragging, then use copy_to_clipboard with key name 'selected_text'"
"Press Ctrl+A to select all, then use copy_to_clipboard with key name 'full_content'"
```

## Advanced Patterns

### Extracting from Read-Only Fields

```text theme={null}
"Many legacy systems have read-only fields that can't be typed into but can be copied. 
For the patient ID field (which is disabled), click on it three times to select the 
value, then use copy_to_clipboard with key name 'patient_id' to extract it."
```

### Copying from Non-Input Elements

```text theme={null}
"The order confirmation number appears as plain text (not in an input field). 
Click and drag to select it, then use copy_to_clipboard with key name 
'confirmation_number' to save it as {{confirmation_number}}"
```

### Extracting Multiple Values in Sequence

```text theme={null}
"On the summary page, extract the following values by copying each:
1. Select the customer ID and use copy_to_clipboard with key name 'customer_id'
2. Select the order date and use copy_to_clipboard with key name 'order_date'
3. Select the total amount and use copy_to_clipboard with key name 'total_amount'

Include all three values in the workflow output: {{customer_id}}, {{order_date}}, {{total_amount}}"
```

### Combining with Data Validation

```text theme={null}
"Copy the account number using copy_to_clipboard with key name 'account_num'. 
Then use execute_terminal_command to validate it:
'if ('{{account_num}}' -match '^\d{10}$') { Write-Output 'Valid' } else { Write-Output 'Invalid' }'

If invalid, use declare_task_failed to stop the workflow."
```

## Tips for Reliable Copying

<Tip>
  **Selection is Key**: The quality of your clipboard capture depends entirely on proper text selection. Be explicit about the selection method (triple-click, Ctrl+A, drag, etc.)
</Tip>

<Tip>
  **Wait After Selection**: If the system is slow, consider adding a brief wait between selection and copy: "wait 0.5 seconds, then use copy\_to\_clipboard"
</Tip>

<Tip>
  **Verify the Copy**: For critical data, you can verify: "use copy\_to\_clipboard with key name 'value', then type `{{value}}` into the verification field to confirm it was captured correctly"
</Tip>

## Clipboard vs Vision Extraction: Detailed Comparison

| Aspect               | Copy to Clipboard                    | Vision-Based ([focused\_action](/workflow-prompting/focused-action) / [extract\_prompt](/workflow-prompting/extract-prompt)) |
| -------------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
| **Text Requirement** | ✅ Text must be selectable & copyable | ✅ Works with ANY visible text (even non-copyable)                                                                            |
| **Speed**            | ⚡ Instant (no AI inference)          | 🐌 2-5 seconds per extraction                                                                                                |
| **Accuracy**         | 📍 Deterministic, byte-exact         | 🎯 Interpretation-based, may vary                                                                                            |
| **Selection**        | ✋ Requires explicit text selection   | 👁️ Reads from screenshot automatically                                                                                      |
| **Use Case**         | Copyable fields, IDs, numbers, dates | Non-copyable text, images, charts, PDFs                                                                                      |
| **Cost**             | 💰 No AI tokens                      | 💳 Uses vision model tokens                                                                                                  |
| **Reliability**      | ✅ If copy works, always succeeds     | ⚠️ Depends on OCR/vision quality                                                                                             |
| **Format**           | 📝 Literal clipboard text            | 🧠 AI interprets and formats                                                                                                 |

### Real-World Scenario

**Extracting an Account Number:**

**With `copy_to_clipboard` (Deterministic)**

```text theme={null}
"Triple-click the account number field and use copy_to_clipboard with 
key name 'account_number' to save it"
```

Result: `"1234567890"` (exact text, instant)

**With `focused_action` (Vision-Based)**

```text theme={null}
"Use focused_action to locate and extract the account number from the screen"
```

Result: `"Account number: 1234567890"` or `"1234567890"` (interpreted, may include extra text)

<Tip>
  **Choose clipboard for**: Selectable text fields (IDs, account numbers, dates, amounts) where you want exact text without interpretation.

  **Choose vision for**: Non-copyable content (images, PDFs, scanned docs, charts), tables, or when text isn't selectable/copyable.
</Tip>

## Example Workflow with Output Schema

Here's a complete workflow that demonstrates clipboard extraction with automatic output generation:

### Define Output Schema

```json theme={null}
{
  "patient_mrn": "string",
  "date_of_birth": "string",
  "latest_lab_result": "string",
  "lab_date": "string"
}
```

### Workflow Instructions

```text theme={null}
"Log into the medical records system with username {username} and password {$password}.

Navigate to the patient search and search for patient name {patient_name}.

Click on the matching patient record to open their file.

In the patient demographics section:
1. Triple-click on the Medical Record Number field and use copy_to_clipboard 
   with key name 'patient_mrn' to capture it as {{patient_mrn}}
2. Triple-click on the Date of Birth field and use copy_to_clipboard 
   with key name 'date_of_birth' to capture it as {{date_of_birth}}

Navigate to the 'Recent Labs' tab.

Use focused_action to find the most recent lab result row and extract:
- The result value, save as {{latest_lab_result}}
- The lab date, save as {{lab_date}}

That's it! The runtime values (patient_mrn, date_of_birth, latest_lab_result, 
lab_date) will automatically be transformed into the final output_data JSON 
matching your schema."
```

### What Happens Behind the Scenes

1. `copy_to_clipboard` captures exact text from fields → saved as runtime variables
2. `focused_action` extracts additional data → saved as runtime variables
3. At run completion, Cyberdesk transforms all runtime values into structured `output_data`:
   ```json theme={null}
   {
     "patient_mrn": "MRN12345",
     "date_of_birth": "1985-03-15",
     "latest_lab_result": "Negative",
     "lab_date": "2024-10-20"
   }
   ```

<Info>
  No manual output construction needed! Just extract the values with `copy_to_clipboard` and `focused_action`, and Cyberdesk handles the rest.
</Info>

## Best of Both Worlds: Hybrid Extraction

For maximum reliability and efficiency, combine both methods in a single workflow:

```text theme={null}
"Extract the following customer data:

Use copy_to_clipboard for copyable text fields (fast, deterministic):
- Customer ID (triple-click the ID field, use copy_to_clipboard with key name 'customer_id')
- Account Number (triple-click, use copy_to_clipboard with key name 'account_number')
- Phone Number (triple-click, use copy_to_clipboard with key name 'phone')

Use focused_action for non-copyable or complex content:
- Purchase history table (use focused_action to extract as JSON array, save as {{purchase_history}})
- Account status badge image (use focused_action to read the status, save as {{account_status}})
- Scanned signature image (use focused_action to verify if signature is present, save as {{signature_verified}})

All values will be included in the final output_data JSON automatically."
```

<Tip>
  **Hybrid Strategy**: Use `copy_to_clipboard` for selectable text fields (faster, deterministic), and `focused_action` for non-copyable content (images, PDFs, charts) or complex data that requires interpretation. You get speed where possible, and vision where necessary!
</Tip>

## Troubleshooting

### Clipboard is Empty

If the clipboard returns empty after `copy_to_clipboard`:

* Ensure text was properly selected before copying
* Some applications block clipboard access - try a different selection method
* Consider adding a small wait after selection: "wait 0.3 seconds before copying"
* **Fallback**: Use `focused_action` to extract via vision instead

### Wrong Value Captured

If the wrong text is captured:

* Be more specific about the selection method
* Use visual cues: "the field with the label 'Account #'"
* Take a screenshot before copying to verify the selection
* **Alternative**: Switch to `focused_action` for that specific field

### Application Doesn't Support Ctrl+C

Some legacy applications may not support standard copy:

* Try using the application's menu: "right-click and select Copy"
* Use keyboard alternatives: "press F2 to edit, then Ctrl+A and Ctrl+C"
* **Best solution**: Use `focused_action` with vision-based extraction instead

### Text is Not Selectable (Use Vision Instead)

Some scenarios where clipboard won't work and you **must use vision-based extraction**:

**Text in Images**

```text theme={null}
❌ "Copy the patient name from the scanned ID card image"
✅ "Use focused_action to read the patient name from the scanned ID card image"
```

**PDF Documents**

```text theme={null}
❌ "Copy the total from the PDF invoice"
✅ "Use focused_action to extract the invoice total from the PDF"
```

**Chart/Graph Data**

```text theme={null}
❌ "Copy the revenue number from the sales chart"  
✅ "Use focused_action to read the revenue value shown in the sales chart"
```

**Non-Selectable UI Labels**

```text theme={null}
❌ "Copy the status text from the colored badge"
✅ "Use focused_action to read the status shown in the badge (likely 'Active', 'Pending', or 'Disabled')"
```

<Warning>
  If text is displayed as an image, graphic, or in a non-selectable format (common in legacy systems, PDFs, or scanned documents), `copy_to_clipboard` will fail. Always use vision-based extraction (`focused_action` or `extract_prompt`) for non-copyable content.
</Warning>
