Extension: Gemini (Paste Selection)

Description: Opens Google Gemini in the default browser and pastes the selected text.

Notes for Reviewer:

  • Why AppleScript? Gemini does not currently support a URL scheme to pre-fill the prompt (e.g., ?q=text does not work). Therefore, this extension uses AppleScript to open the URL and simulate Cmd+V to paste the selection.

  • Behavior: It performs a copy-selection first, opens https://gemini.google.com/app, waits 1.0 second for the tab to load/focus, and then pastes.

  • No Auto-Submit: It deliberately does not simulate the “Enter” key, allowing the user to refine the prompt before sending.

Extension: Gemini (Paste Selection) #popclip
name: Gemini
icon: symbol:sparkles
description: Open Gemini and paste the selection.
before: copy-selection
applescript: |
  open location "https://gemini.google.com/app"
  delay 1.0
  tell application "System Events" to keystroke "v" using command down
1 Like

Hi everyone,

I created an extension to send selected text to Google Gemini. I just revised it.

Since Gemini’s web app (gemini.google.com) currently doesn’t support URL query parameters to pre-fill the prompt (like ?q=text), the standard PopClip URL action doesn’t work.

This extension solves that by using AppleScript to simulate the workflow. It is designed to be non-destructive to your clipboard.

Key Features:

  • Universal Support: Works with your system’s default browser (Chrome, Arc, Safari, Edge, etc.) using the shell open command.

  • Clipboard Restoration: It temporarily copies the selection to paste it, but restores your original clipboard content immediately after. You won’t lose what you previously copied.

  • No Auto-Submit: It pastes the text but leaves the cursor in the input box. This allows you to add specific instructions (e.g., “Summarize this:”, “Translate to French:”) before hitting Enter.

#popclip
name: Gemini
icon: symbol:sparkles
description: Open Gemini, paste selection, and restore original clipboard.
applescript: |
  -- 1. Backup: Save current clipboard content
  try
    set originalClipboard to the clipboard
  on error
    set originalClipboard to ""
  end try
  
  -- 2. Copy: Simulate Cmd+C to grab selection
  tell application "System Events" to keystroke "c" using command down
  delay 0.2
  
  -- 3. Open: Launch default browser via shell to ensure activation
  do shell script "open 'https://gemini.google.com/app'"
  
  -- 4. Wait: Adjust this delay if your browser/network is slower (1.0 is standard)
  delay 1.0
  
  -- 5. Paste: Simulate Cmd+V
  tell application "System Events" to keystroke "v" using command down
  
  -- 6. Restore: Wait for paste to finish, then restore original clipboard
  delay 0.5
  set the clipboard to originalClipboard

Very cool. I just installed Gemini and noticed that when you select text in its output, the PopClip menu line doesn’t appear. (Command-C does work to copy the text.)

My Popclip menu appeared in my chrome and in my Mac Gemini App while selecting the texts.

“I just installed Gemini and noticed that when you select text in its output, the PopClip menu line doesn’t appear.”

Same for me man, it’s so frustrating.

What versions of PopClip and Gemini are you using? It’s working for me Gemini 1.64.1.362 with PopClip 2025.9.2.

1 Like

Wasn’t installing. Had to tweak it.

#popclip
name: Gemini
icon: symbol:sparkles
description: Open Gemini and paste the selection.
before: copy
applescript: |
open location "``https://gemini.google.com/app``"
delay 1.0
tell application "System Events" to keystroke "v" using command down

1 Like

Using the latest version of PopClip, version 2026.8.1 (6221), here’s how I’d do it now:

The difference is that we can now press a key from JavaScript, so we don’t have to do it in AppleScript (unless you really like AppleScript!)

// #popclip
// name: Gemini
// icon: symbol:sparkles
// description: Open Gemini and paste the selection.
await popclip.openUrl("https://gemini.google.com/app");
await sleep(1000);
pasteboard.text = popclip.input.text;
await popclip.pressKey("command v");
2 Likes

Still 6220 on setapp. Wont install.

Doh! I forgot to hit the Setapp release button :grimacing: Should be out in about half an hour.

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.

1 Like