Clipboard
The Clipboard Aptitude provides the ability to interact with your clipboard on your system.
API
Example
Permissions

listen

Provides the Loop author with the capability to inspect all values that are copied to your clipboard while the listener is active. Clipboard events from the Olive Helps desktop app can be filtered out from the responses.
1
import { clipboard } from '@oliveai/ldk';
2
3
// When true, clipboard events emitted while Olive Helps is focused are picked up by the callback
4
const listenToOliveHelpsEvents = true;
5
// Function that is called after listen() detects a clipboard event.
6
// Provides the text from the event as the first argument of the callback
7
const callback = (clipboardText) => {
8
console.log(`Received clipboard text: ${clipboardText}`);
9
};
10
11
clipboard.listen(listenToOliveHelpsEvents, callback);
Copied!

read

Get the current contents of the clipboard at the moment when the function is called.
1
import { clipboard } from '@oliveai/ldk';
2
3
// Function that is called after read() is successful
4
// Provides the text on the clipboard when read() was executed
5
const callback = (clipboardContents) => {
6
console.log(`Read from the clipboard: ${clipboardContents}`);
7
};
8
9
clipboard.read().then(callback);
Copied!

write

Set the contents of clipboard, overwriting its current value.
1
import { clipboard } from '@oliveai/ldk';
2
3
// Function that is called after write() is successful
4
const callback = () => {
5
console.log('Wrote to the keyboard!');
6
};
7
8
clipboard.write('Message to clipboard').then(callback);
Copied!
Imagine you are trying to display an information Whisper about a physician to their client. One of the ways that you could do this is using the Clipboard Aptitude.
To do this, you would use the listen() function. It adds a sensor to the Loop, catching all incoming changes to a user's clipboard. This includes both copy and cut events.
In addition to detecting the events, it allows you to provide a callback to respond to any incoming events.
Let's look at an example to better illustrate the point
1
import { clipboard, whisper } from '@oliveai/ldk';
2
3
const listenToOliveHelpsEvents = false;
4
const listOfImportantWords = ['Foo', 'Bar'];
5
6
const clipboardListen = () =>
7
clipboard.listen(listenToOliveHelpsEvents, (clipboardText) => {
8
if (listOfImportantWords.includes(clipboardText)) {
9
whisper.create({
10
// Information card whisper
11
});
12
} else {
13
whisper.create({
14
// No results whisper
15
})
16
}
17
});
Copied!
In this example, if you were to copy the string Foo or Barto their clipboard, it would trigger the Whisper displaying an information card. Anything else would cause the Loop to show the "no results" Whisper.
Another thing to inspect in this code is the value of listenToOliveHelpsEvents . Because this value is false in this code, that means that any clipboard events that occur from the Olive Helps window would not trigger the callback of the listener.
To use the Clipboard aptitude, simply set the following permissions in your package.json under the ldk object.
1
...
2
"ldk": {
3
"permissions": {
4
"clipboard": {},
5
...
6
}
7
},
8
...
Copied!
Last modified 5d ago
Copy link