Skip to content

Instantly share code, notes, and snippets.

@goerz
Created August 1, 2010 17:57
Show Gist options
  • Save goerz/503579 to your computer and use it in GitHub Desktop.
Save goerz/503579 to your computer and use it in GitHub Desktop.
filter.pl: Filter the contents of the KDE clipboard through any pipe
#!/usr/bin/perl -w
use strict;
my $historyfile = glob '~/.filter.pl.last';
my $command = "";
system("touch $historyfile");
open(HIST, "$historyfile") or die "Can't open file: $!";
$command = <HIST>;
chomp $command;
close HIST;
$command = readpipe('kdialog --title "filter.pl" -inputbox "Insert command" "'."$command".'"');
# delete everything after the first newline
if ($command =~ m/(^.*)\n/){
$command = $1;
}
unless ($command eq ""){
system('dcop klipper klipper setClipboardContents "`dcop klipper klipper getClipboardContents | '."$command".'`"');
open(HIST, ">$historyfile") or die "Can't open file: $!";
print HIST $command;
close HIST;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment