Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

OS-integrated Perl

by Sprad (Hermit)
on Mar 01, 2004 at 21:18 UTC ( [id://333056]=perlquestion: print w/replies, xml ) Need Help??

Sprad has asked for the wisdom of the Perl Monks concerning the following question:

I want the ability to highlight a bit of text in any program and run a Perl script on it. Either by pulling up a context-sensitive menu, or hitting some predefined keyboard shortcut, or something equally simple. The results should either be placed on the clipboard or overwrite the highlighted text, depending on the script's function and whether or not the text I highlighted is editable.

Does this exist on any platform?

---
A fair fight is a sign of poor planning.

Replies are listed 'Best First'.
Re: OS-integrated Perl
by neniro (Priest) on Mar 01, 2004 at 21:32 UTC
    how about vi:
    :2,8!./foo.pl
    uses foo.pl on line 2..8.
Re: OS-integrated Perl
by Abigail-II (Bishop) on Mar 01, 2004 at 21:27 UTC
    I've the following in my .fvwm2rc file:
    Key F11 A N Exec /usr/bin/netscape -noraise -remote " +openURL(`perl -MTk -e '$_=MainWindow->new->SelectionGet;$_=~s/\s*\+// +g;print'`,new_window)"
    What it does is to allow me to select a URL, and then hit F11 to have it open in Netscape.

    Abigail

Re: OS-integrated Perl
by hardburn (Abbot) on Mar 01, 2004 at 21:24 UTC

    I'm sure it can be done in emacs, which qualifies as it's own OS . . .

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Re: OS-integrated Perl
by BrowserUk (Patriarch) on Mar 01, 2004 at 23:23 UTC

    Set this going in the background somewhere ( eg. start /b clippy.pl ) or you could daemonise it with Win32::Daemon and then whenever you cut or copy some text into the clipboard, when you paste it, it will have been ucfirst'd.

    Of course, as is that is just annoying when you don't want it done (which is exactly what happened to me when I just c&p'd the program code below:), but it illustrates the idea.

    There are various ways you could control the behaviour. Pop up a dialog with a set of buttons control what modification is made. Or prefix the text with an instruction telling it what to do, and do nothing if a known prefix is not found. That's left as an exercise for the reader.

    #! perl -slw use strict; use Win32::Clipboard; my $clip = Win32::Clipboard->new; while( $clip->WaitForChange ) { next unless $clip->IsText; my $text = $clip->GetText(); ## Grab it $text =~ s[\b(\S+)\b][ ucfirst $1 ]eg; ## Modify it $clip->Set( $text ); ## Put it back so the user can paste it. } __END__ the quick brown fox The Quick Brown Fox

    I frequently c&p text into a free, web-based language translation service. With the addition of some LWP or WWW::Mechanise, this could be really useful.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
Re: OS-integrated Perl
by John M. Dlugosz (Monsignor) on Mar 01, 2004 at 23:32 UTC
    PGP has a "tray" icon in Windows that offers, among other things, to process the text on the clipboard and process the selection in the current window. That sounds like the same kind of stuff you are talking about.

    A really simple way would be to copy the text to the clipboard, and then run a program that takes a script from the clipboard instead of a file. Make that run from an icon somewhere or bind to a global hotkey or whatever. That should be do-able on any modern GUI.

Re: OS-integrated Perl
by ambrus (Abbot) on Mar 02, 2004 at 15:17 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://333056]
Approved by halley
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2025-05-21 02:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.