Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • by jmason (3282) on 2005.02.24 18:19 (#38520) Homepage
    Cutting is hard, because you need an app that'll "own" the selection, and deal with paste requests.

    Here's a short TCL/Tk script that does it, based on something similar I had for pasting. It's quite suboptimal, but should give the idea. Reimplementing in perl, and incorporating some smart forking and one-daemon-per-desktop code would be really nifty! ;)

    #!/usr/bin/wish -f
    # xcopy - set the current string selection to whatever's passed in on stdin

    set text [read stdin]

    # Set up the data handler ready for incoming requests
    selection handle -selection PRIMARY . getData
    # Now we grab the selection itself
    selection own -command lost -selection PRIMARY .

    proc getData {offset maxChars} {
      return [string range $::text $offset [expr {$offset+$maxChars}]]
    }

    proc lost {} {
      set text ""
      exit
    }