4

I'm working on a Gnome Shell Extensions and I can't find any documentation on how to copy some string into the clipboard for the user.

I searched the Gnome extensions git but without any success.

Thank you for your help! :)

Cyril N.
  • 38,875
  • 36
  • 142
  • 243

1 Answers1

9

to set the primary clipboard:

St.Clipboard.get_default().set_text(St.ClipboardType.PRIMARY, 'text');

to get the primary clipboard:

St.Clipboard.get_default().get_text(St.ClipboardType.PRIMARY);

There also is the St.ClipboardType.CLIPBOARD buffer.

(source code)

Otto Allmendinger
  • 27,448
  • 7
  • 68
  • 79
Omid
  • 460
  • 3
  • 13
  • 4
    Gnome Shell is a really pain in the ass regarding the documentation. It take so long to find what you need, it's sad. But thanks for your post, I'm sure it well help others as well :) – Cyril N. May 11 '12 at 08:40
  • 2
    I'm using `GNOME Shell 3.22.3` and I had to add a callback as a second parameter of the get_text() call. So, in order to retrieve from the clipboard, this worked for me: `St.Clipboard.get_default().get_text(St.ClipboardType.PRIMARY, (clipboard, text) => { /* Callback code here. */ })` – luvejo Jul 05 '18 at 18:28
  • I had to use St.ClipboardType.CLIPBOARD instead of St.ClipboardType.PRIMARY – 0x777C Apr 19 '19 at 14:32