Advertisement
palik

Perl/MAC OS; KeePass; Copy Item-Password to Clipboard

Mar 24th, 2014
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.98 KB | None | 0 0
  1. use v5.10;
  2. use strict;
  3. use warnings;
  4.  
  5. use File::KeePass;
  6. use Getopt::Long;
  7. use IO::Prompt;
  8. use Data::Dump 'dump';
  9. use Mac::Pasteboard;
  10.  
  11. my $db_file;
  12. GetOptions('file=s' => \$db_file);
  13. $db_file || die "usage:\nperl $0 --file KeePass.kdb";
  14. -r $db_file || die "can't read $db_file";
  15.  
  16. my $pwd = IO::Prompt::prompt("$db_file password? ", -e => '*');
  17.  
  18. my $k = File::KeePass->load_db($db_file, $pwd);
  19.  
  20. my $pattern = IO::Prompt::prompt("look for? ");
  21.  
  22. my @entries = $k->find_entries({ 'title =~' => qr/$pattern/i });
  23. say 'found ', scalar(@entries), ' entries';
  24.  
  25. $k->unlock;
  26. for (my $i = 0; $i <= $#entries; $i++) {
  27.     say join "\t", $i + 1, @{ $entries[$i] }{qw/title url username/};
  28.  
  29.     if (IO::Prompt::prompt('copy password? [y/n] ', -tys => 0.2)) {
  30.         my $pb = Mac::Pasteboard->new();
  31.         $pb->clear();
  32.         $pb->copy($entries[$i]->{password});
  33.         last;
  34.     } ## end if (IO::Prompt::prompt...)
  35. } ## end for (my $i = 0; $i <= $#entries...)
  36.  
  37. $k->lock;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement