If you’re a *nix user, this is one way your life is significantly better. In fact, it’s my experience doing this in Ubuntu that made me look for a solution in Windows. This method has existed since shortly after perl was brought over – I’m certainly not due any credit for creating anything – but I did have the sense to go looking for it. (The idea was original to my brain, if not the world, and it was a good idea, even if someone else had it first.)
Now, what are we doing? We’re creating system commands. We’re creating a keystroke combination (like Ctrl+Shift+C) that works as a program shortcut. What’s new about this? Well, nothing, except that we’re going to add some twists to make them really work for us.
We can perform tasks of any complexity, but let’s look at a practical example. The Firefox extension, FireFTP, allows for easy file transfer between your local and remote hosts. It’s FTP, no big deal. And, like most FTP programs, you’re able to navigate in your local host as well as the remote host so that you can put files from one side to the other. So what, you ask?
Sometimes, either because the program doesn’t support step-locking, or because we’re intentionally not working in mirrored folders, the paths of the local and remote server end up out of sync. In the case of FireFTP, you can’t simply copy the path from one side to the other, because the file separators are opposite. This is where Perl and our shortcuts come into play.
With a keystroke (Ctrl+Shift+C), I can perform the action of replacing the separators in one path with the opposite ones needed for the other. I can, for example, copy one of the paths with Ctrl+C, make c:/perl/bin/perl.exe become c:perlbinperl.exe using Ctrl+Shift+C, and then paste my new path using Ctrl+V. But how?!
ActiveState perl for Windows installs a perl executable called wperl.exe in C:/perl/bin/. You can pass perl scripts as arguments to this executable in the form of strings. (This is twist #1.) By setting up custom windows shortcuts to wperl.exe and supplying a script as an argument, you effectively create a system command that can do anything Perl can do (This is twist #2).
Perl, itself, has lots of access to Win32 via different modules. The module we care about is Win32::Clipboard, which allows us to modify the clipboard contents as a string. I’ll post the script for that below. Here’s how you can set up your shortcut. You can copy the values in the image to get it working. (Right-click on the desktop -> new -> shortcut) You’ll need ActiveState perl.
Of course, the script below will need to live in c:/perls/ if that’s the path you supply as the argument (per the image).
#!/usr/bin/perl use Win32::Clipboard; $CLIP = Win32::Clipboard(); $text = $CLIP->GetText(); if ($text =~ ///) { $text =~ s///\/g; } else { $text =~ s/\///g; } #print "Clipboard contains: ", $CLIP->Get(), "n"; $CLIP->Empty(); $CLIP->Set($text);

