Skip to content

Instantly share code, notes, and snippets.

@davebarnwell
Last active July 30, 2017 16:33
Show Gist options
  • Save davebarnwell/11c25690972ecc1452a41fde35dd66b2 to your computer and use it in GitHub Desktop.
Save davebarnwell/11c25690972ecc1452a41fde35dd66b2 to your computer and use it in GitHub Desktop.
PHP to copy a string to the mac os x paste board
<?php
function copy2clipboard($string){
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "a.txt", "a") // stderr is a file to write to
);
$process = proc_open('pbcopy', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $string);
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
return $return_value;
}
}
copy2clipboard('The string to copy to the paste board');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment