I tested several variants of the Gemini PopClip extension and ended up with two reliable versions: one for Google Chrome and one for Safari.
Both versions:
- Open Gemini.
- Wrap the selected text in
<selected_text> tags.
- Add an
Instructions: section after the selected text.
- Leave the prompt unsent so additional instructions can be added manually.
- Restore the original clipboard contents after pasting.
- Preserve the complete pasteboard content, not only plain text.
Google Chrome version
This version explicitly opens Chrome, waits until Gemini’s editable input field exists, focuses it, and then pastes the text.
// #popclip
// name: Gemini Chrome
// icon: symbol:sparkles
// description: Open Gemini in Chrome and paste selection with instructions.
// entitlements: [script]
const text = `<selected_text>
${popclip.input.text}
</selected_text>
Instructions:
`;
const originalClipboard = pasteboard.content;
try {
await popclip.runAppleScript(`
tell application "Google Chrome"
activate
open location "https://gemini.google.com/app"
set inputReady to false
repeat 20 times
delay 0.5
set resultText to execute active tab of front window javascript "
(() => {
const input = document.querySelector(
'rich-textarea [contenteditable=true], [contenteditable=true][role=textbox], textarea'
);
if (!input) return 'false';
input.focus();
return 'true';
})()
"
if resultText is "true" or resultText is true then
set inputReady to true
exit repeat
end if
end repeat
if inputReady is false then
error "Gemini input field was not found."
end if
end tell
`);
pasteboard.text = text;
await popclip.pressKey("command v");
await sleep(500);
} finally {
pasteboard.content = originalClipboard;
}
Safari version
This version explicitly opens Safari, waits one second, and uses System Events to send Command-V. This was more reliable than trying to focus Gemini through Safari JavaScript.
// #popclip
// name: Gemini Safari
// icon: symbol:sparkles
// description: Open Gemini in Safari and paste selection.
// entitlements: [script]
const text = `<selected_text>
${popclip.input.text}
</selected_text>
Instructions:
`;
const originalClipboard = pasteboard.content;
try {
await popclip.runAppleScript(`
tell application "Safari"
activate
open location "https://gemini.google.com/app"
end tell
`);
await sleep(1000);
pasteboard.text = text;
await sleep(200);
await popclip.runAppleScript(`
tell application "System Events"
keystroke "v" using command down
end tell
`);
await sleep(500);
} finally {
pasteboard.content = originalClipboard;
}
Problems encountered
The developer’s minimal version was:
await popclip.openUrl("https://gemini.google.com/app");
await sleep(1000);
pasteboard.text = popclip.input.text;
await popclip.pressKey("command v");
In my environment, this opened Gemini successfully and placed the correct text on the clipboard, but the Gemini input field remained empty. Manually clicking the input field and pressing Command-V worked.
Increasing the delay to 2.5 seconds also failed. This showed that the main problem was not simply page-loading time. The browser page was open, but the Gemini input field did not have keyboard focus.
The Chrome version therefore uses Chrome AppleScript to focus the editable input field before pasting. The Safari JavaScript focus approach was unreliable, so the Safari version uses System Events to send Command-V instead.
I also tested:
await popclip.pasteText(text, { restore: true });
Although this is supported by the PopClip API, it was unreliable in this Gemini workflow. Manually saving pasteboard.content, pasting, and restoring it in a finally block was more reliable.
The Chrome version requires Chrome’s “Allow JavaScript from Apple Events” option. The Safari version requires the usual macOS Accessibility permission for System Events.