How do I save data to the clipboard on MacOSX in C

196 views Asked by At

I'm attempting a work around to a very nasty problem that involves being locked down in a CUPS printing service filter. The application is unable to write outside of it's domain as a filter program. & thus I wanted to give saving a string to the clipboard a go, to get it out of the program and readable by another. The Exchange will happen so quickly the user won't know it even occurred.

So is a way to write xData to the X clipboard on OSX in C?

Mike

1

There are 1 answers

2
r3mainer On

As far as I can tell, OS X provides an interface to the clipboard functions in Objective C, but not plain C.

However, you can simply open a pipe to the pbcopy command line utility as follows:

#include <stdio.h>
int main() {
  FILE *p = popen("/usr/bin/pbcopy","w");
  fprintf(p,"Hello world");  /* << Copy this to clipboard */
  pclose(p);
  return 0;
}