Created
February 4, 2012 12:24
-
-
Save jfthuong/1737527 to your computer and use it in GitHub Desktop.
Perl script to convert a Lotus Notes link into a notes:// protocol link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
$|=1; | |
eval { | |
#- Access the Clipboard -# | |
use Win32::Clipboard; | |
my $CLIP = Win32::Clipboard(); | |
my $input; | |
if ($CLIP->IsText()) { | |
$input = $CLIP->Get() or die "No input data found!"; | |
$CLIP->Set( transform_link($input) ); | |
} else { | |
die "Clipboard contains data that is not text!\n"; | |
} | |
}; | |
if ($@) { print "$@\n...Press ENTER to continue...\n\n";<STDIN>; } else {} | |
sub transform_link { | |
my $link = shift or die "Error: no input has been specified\n"; | |
#Remove all spaces | |
$link =~ s/\s+//g; | |
#REPOSITORY | |
if ($link =~ /<HINT>CN=(\w+)/) { | |
$link = "Notes://$1#/#" . $link; | |
} else { | |
print "LINK = $link\n"; | |
die "Error: cannot find HINT\n"; | |
} | |
#REPLICA | |
unless ($link =~ s%^(.*)#/#.*<REPLICA(\w+):(\w+)>%$1/$2$3/%) { | |
print "LINK = $link\n\n"; | |
die "Error: cannot find REPLICA\n"; | |
} | |
#VIEW | |
unless ($link =~ s%<VIEWOF(\w+):(\w+)-ON(\w+):(\w+)>%$1$2$3$4/%) { | |
print "LINK = $link\n"; | |
die "Error: cannot find VIEW\n"; | |
} | |
#NOTE | |
unless ($link =~ s%<NOTEOF(\w+):(\w+)-ON(\w+):(\w+)>.*$%$1$2$3$4%) { | |
print "LINK = $link\n"; | |
die "Error: cannot find NOTE\n"; | |
} | |
return $link; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment