Share clipboard
A shortcut that reads your clipboard, lets you choose what to do with it, and acts on your choice.
What you'll learn
- Variables and bindings with
constandlet - Control flow with
menu - String interpolation with
${} - Device actions, including
Device.getClipboardandDevice.copyToClipboard - Sharing actions, including
Sharing.share - Text actions, including
Text.changeCase
Source
import Device;
import Sharing;
import Text;
import Notification;
shortcut {
name: "Share Clipboard",
description: "Read clipboard and share or transform it",
}
const text = Device.getClipboard();
menu "What do you want to do?" {
case "Share" {
Sharing.share(text);
}
case "Copy Uppercase" {
const upper = Text.changeCase(text, "UPPERCASE");
Device.copyToClipboard(upper);
Notification.showAlert("Copied to clipboard!");
}
case "Show" {
Notification.showAlert("Clipboard: ${text}");
}
}compilation failed with 1 diagnostic
Shortcuts preview coming soon
How it works
Device.getClipboard() reads the clipboard into text. The compiler emits a "Get Clipboard" action and binds its magic-variable output to text.
The menu block provides three options:
Sharepasses the clipboard text to the system share sheet withSharing.share().Copy Uppercasetransforms the text withText.changeCase(), writes it to the clipboard, and displays a confirmation.Showinsertstextinto an alert with string interpolation.