[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Clipboard Transfer via AppleTalk



Hm, found out that MacPerl doesn't like to do the transfer if it is in the
background.  This is fixed (the server) to make MacPerl the front app, then
to make the previous front app front again when done.

#!perl -w
# clipboard_server.plx

package Dartmouth;
MacPerl::LoadExternals("Clipboard.XFCN");

package main;
use strict;
use IO::Socket;
use Mac::Processes;
my($answer, $client, $server);

$server = IO::Socket::APPLETALK->new(
  Object  => 'ClipboardServer1',
  Listen  => 1,
) or die('Cannot start server');

while ($client = $server->accept()) {
  my $pr = GetFrontProcess();
  SetFrontProcess(get_front());sleep(1);
  my $do = <$client>;
  my @data;
  while (<$client>) {
    last if /^END\n$/;
    push @data, $_;
  }
  if ($do =~ /^Get/) {
    print $client "Sending:\n", Dartmouth::Clipboard();
  } else {
    Dartmouth::Clipboard(join('', @data));
    print $client "Saving:\n", @data;
  }
  close($client);
  # exit;  # always run server?
  SetFrontProcess($pr);
}

sub get_front {
  my %x;
  foreach (keys %Process) {
    $x{$Process{$_}->processSignature} = $_;
  }
  return $x{McPL};
}

__END__

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch