Copying text to clipboard in UNIX

K

kp

Hi all,

I want to copy a text to clipboard in UNIX.

Is there a way to do this in Perl?
Or should I use some other language?

Thanks,
Krishna
 
M

Mumia W.

kp said:
Hi all,

I want to copy a text to clipboard in UNIX.

Is there a way to do this in Perl?
Or should I use some other language?

Thanks,
Krishna

Although Tk originated with TCL, it's available for Perl, and it can
manipulate the selection for you:

#!/usr/bin/perl
use strict;
use warnings;
use Tk;

# Let's be funny and name the window $winxp.
my $winxp = MainWindow->new();
$winxp->Label (-text => 'Hello World')->pack();
$winxp->Button (-text => 'Quit' ,
-command => [ $winxp => 'destroy' ]
)->pack; $winxp->SelectionClear ();
$winxp->SelectionHandle (\&myhandler);
$winxp->SelectionOwn ();
MainLoop;

sub myhandler {
my ($offset, $maxChars) = @_;
return "This is text from Perl.";
}

# Credits to the authors of the perl-tk manpage.


Read the docs;
$ man perl-tk
$ man Tk::Selection
 
K

kp

Thanks Mumia,

My requirement is somewhat different. I want the functionality of this
in a script or command. :: select a text with a mouse - the text will
be copied to clipboard - and we can insert using Shift+Ins

I have a perl script (put_path.pl). This will keep the current path in
clipboard. (I will use this later in other terminals).

put_path.pl.

$path = `pwd`;
TODO: I need to paste this path in clipboard.

Thanks in advance.
 
D

Dave

kp said:
Thanks Mumia,

My requirement is somewhat different. I want the functionality of this
in a script or command. :: select a text with a mouse - the text will
be copied to clipboard - and we can insert using Shift+Ins

I have a perl script (put_path.pl). This will keep the current path in
clipboard. (I will use this later in other terminals).

put_path.pl.

$path = `pwd`;
TODO: I need to paste this path in clipboard.

Thanks in advance.

Does the CPAN module Clipboard go anywhere to meeting your needs?
 
K

kp

Dave,

Can you repost the link about CPAN? It is not working.
I need a simple function that will copy a text to standard clipboard in
UNIX.

Thanks,
Krishna
 
D

Dr.Ruud

kp schreef:
I want to copy a text to clipboard in UNIX.

Is there a way to do this in Perl?
Or should I use some other language?

Do you need to copy text just from within the Perl-program in the
foreground? As Dave mentioned, check out CPAN module Clipboard.

Or do you need a background process, possibly written in Perl, that
would do it for any other program running in the active terminal window?
http://en.wikipedia.org/wiki/Daemon_(computer_software)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,578
Latest member
LC_06

Latest Threads

Top