hakobe (owner)

Revisions

gist: 115372 Download_button fork
public
Public Clone URL: git://gist.github.com/115372.git
Embed All Files: show embed
README #
1
2
3
Perl-OSX-Clipboard: Scripts to manipulate a Mac OS X-clipboard.
See: null
 
script/pb_client.pl #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
 
 
script/pb_server.pl #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}