Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created May 21, 2009 09:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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