# Clipboard

The clipboard is a system on the parent OS that handles copying and pasting text, images, and files. This can be interacted with directly through OSL, allowing scripts to read and set the clipboard.

**It's worth noting that the copy/paste functionality in originOS can be unstable at times. This is simply due to the nature of how browsers handle these events. Be prepared for edge cases and unexpected functionality.**

### Setting the Clipboard

There are 2 OSL commands for manipulating the clipboard; `clipboard "set"` allows overwriting the current contents of the clipboard with a new value, while `clipboard "clear"` removes the clipboard's current data.

```js
// data - the value to be copied to the clipboard
//    this is typically a string
clipboard "set" data

// "clear" doesn't require a data argument.
clipboard "clear"
```

### Reading the Clipboard

The clipboard can be read simply through accessing the `clipboard` global variable.

```js
// puts the clipboard's content into the console
log clipboard
```

### Clipboard Events

OSL has two events related to the clipboard, one fires when a copy is detected (typically Ctrl + C or Ctrl + X) and one when a paste is detected (typically Ctrl + V).

```js
window.on("copy", () -> (
   log "Copied text:" + clipboard
))

window.on("paste", () -> (
   log "Pasted text:" + clipboard
))
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://osl.mistium.com/environment/clipboard.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
