Menu

ClipSlapper- A Command-line clipboard utility

January 31, 2015 - Programming

A bit of a shorty today- Basically, I’ve uploaded “ClipSlapper” a new utility program, designed to run on the command-line, which can retrieve or set text data on the Windows clipboard from the command line. In particular it will retrieve and assign data via standard output, which allows it to be used for scripting purposes I suppose.

The source code has been uploaded to github, here.

The actual implementation is fairly straightforward. I used my existing Command Line Parser class to determine command line arguments as easily as possible. As is it only really works with text, but the intent is to also have it work with other data types. Of course, converting those to strings that can be output- or at least bytes- is not always straightforward. An image on the clipboard can be output as a bitmap stream or output as a PNG stream, for example, and it seems ideally that should be determined with even more switches. Currently it just tries to cast the data to a string and write it to the standard output. I was bitten by the use of Windows Forms classes in a console program, in the form of having it basically ignore everything regarding the clipboard- without an error- until I added [STAThread] to the main() routine.

The main purpose for this is that I rather have an affinity for cmd and find myself using it a lot, and having more direct capabilities is useful. I already use BASeParser, an ancient VB6 Expression Evaluator I wrote what feels like a millenium ago, in the form of a front-end command line program to perform calculations. I find it far easier to use than any GUI Calculator program. the closest thing might be using perl with the -e switch, but this way allowed me to customize the Evaluator to add support for a myriad of other capabilities such as sequences.

Hopefully I can get around to improving this Clipboard tool- likely I will only decide to improve the support for non-text types when I find I actually need it, as the case often is.

Have something to say about this post? Comment!