I have tried looking for ways to access Linux clipboard (Access and modify clipboard) but there is no clear solution to the problem. I have seen these post, 1, 2and tried to look for solution, all I could find are either Windows solution or OSX solution for this problem. Is there a formal way to solve this problem? Thank you very much.
Asked
Active
Viewed 896 times
2 Answers
3
The clipboard in Linux does not work similar to how it works under Windows and OS X. There is no separate storage for it, but rather it is an X selection that one application "owns" and will transfer data for when requested. If you wanted to modify the contents then you would need to request the current selection contents, modify that, and then make it available in your application as the new clipboard.

Ignacio Vazquez-Abrams
- 776,304
- 153
- 1,341
- 1,358
-
That's actually interesting, it's a windowing system feature rather than a full blown OS-level feature. Makes it clunkier. – Blindy Oct 03 '15 at 05:24
0
void runproc(char *output, char *proc) {
FILE *fp;
fp = popen(proc, "r");
if (fp == NULL) {
ERRMSG(-1, true, "runproc failure");
}
fgets(output, 4096, fp);
pclose(fp);
}
int cbcopy(char *text) {
/* copies text to the system clipboard
usint xclip command */
char cmd[10240]; // 10K
int rc = 0;
sprintf(cmd, "echo \"%s\" | xclip -selection clipboard", text);
rc = system(cmd);
return rc;
}
char *cbpaste(char *text) {
/* pastes clipboard into text */
char cmd[64]; // 10K
strncpy(cmd, "xclip -o", 10);
runproc(text, cmd);
chomp(text);
return text;
}

MichaelDL
- 57
- 4