Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created May 21, 2009 09:14
Show Gist options
  • Select an option

  • Save hakobe/115372 to your computer and use it in GitHub Desktop.

Select an option

Save hakobe/115372 to your computer and use it in GitHub Desktop.
Perl-OSX-Clipboard: Scripts to manipulate a Mac OS X-clipboard.
See: null
use strict;
use warnings;
use IO::Socket::UNIX;
my $socket_file = shift || '/tmp/pb_server.pl.sock';
my $connection = IO::Socket::UNIX->new(
Type => SOCK_STREAM,
Peer => $socket_file,
) or die $!;
my $data = '';
my $read;
while ($connection->sysread($read, 1024)) {
$data .= $read;
}
print $data;
$connection->close;
use strict;
use warnings;
use IO::Socket::UNIX;
my $socket_file = shift || '/tmp/pb_server.pl.sock';
unlink $socket_file if -e $socket_file;
my $listen = IO::Socket::UNIX->new(
Type => SOCK_STREAM,
Local => $socket_file,
Listen => SOMAXCONN,
) or die $!;
while (my $connection = $listen->accept) {
open my $pbpaste, '-|', 'pbpaste' or next;
my $data;
{
local $/;
$data = <$pbpaste>;
}
$connection->syswrite($data);
$connection->close;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment