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 — storing action results with
constandlet - Control flow — presenting choices with
menu - String interpolation — embedding values in text with
${} - Standard library actions —
getClipboard,setClipboard,share,showAlert
Source
shortcut {
name: "Share Clipboard",
description: "Read clipboard and share or transform it",
}
const text = getClipboard();
menu "What do you want to do?" {
case "Share" {
share(input: text);
}
case "Copy Uppercase" {
const upper = changeCase(text: text, case: "UPPERCASE");
setClipboard(value: upper);
showAlert(text: "Copied to clipboard!");
}
case "Show" {
showAlert(text: "Clipboard: ${text}");
}
}compilation failed with 2 diagnostics
Shortcuts preview coming soon
How it works
The shortcut starts by reading the clipboard into a text variable with getClipboard(). In the Shortcuts app, this is the "Get Clipboard" action, and text becomes its output, the equivalent of a magic variable.
The menu block presents a "Choose from Menu" dialog with three options:
- Share passes the clipboard text to the system share sheet with
share(). - Copy Uppercase transforms the text with
changeCase(), writes the result back to the clipboard withsetClipboard(), and confirms with an alert. - Show displays the clipboard contents in an alert, using string interpolation to embed the
textvariable.