Throw-Away Apps FTW!
- March 7th, 2010
- Posted in General Nerdery
- By AMB
- Write comment
So one of the greatest things about being a hacker is that one has a ready answer to idle thoughts of “I wish my computer did X…” You simply code up a way for it to do what you want. It’s especially nice when what you want it to do is actually rather simple, but just something that no one’s thought to implement yet. (This is all, of course, assuming that Google failed to turn up a good existing solution. Reinventing the wheel makes baby Edsger Dijkstra cry.)
Case in point: on a couple of recent occasions, I’ve thought it’d be nice if I had a way to quickly dump a timestamp to my windows clipboard so that I could drop it into documents. Well, after ten minutes of hacking and a little bit of thrashing at OS integration, I have exactly that.
Basically I wrote a lightweight C# console app that optionally takes a DateTime format string as an argument and does nothing but push a current timestamp to the clipboard. (It applies the format string if provided, otherwise it just uses default formatting.) I put the executable in an easy-to-remember path (C:\TimeToClipboard\). I then added keys to some of the shell registry entries to add the application (called with my preferred timestamp format) to filesystem context menus.
The application code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System; using System.Windows.Forms; namespace TimeToClipboard { class Program { [STAThread] static void Main(string[] args) { if (args.Length > 0) { Clipboard.SetText(DateTime.Now.ToString(args[0])); } else { Clipboard.SetText(DateTime.Now.ToString()); } } } } |
The registry entries:
Keys: HKey_Classes_Root/*/shell/Get Timestamp/command
HKey_Classes_Root/Drive/shell/Get Timestamp/command
HKey_Classes_Root/Folder/shell/Get Timestamp/command
Value: c:\TimeToClipboard\TimeToClipboard.exe “yyyy.M.d H:mm:ss”
This worked pretty well, but I couldn’t figure out a way to add the Get Timestamp context menu item to the desktop context menu. I was hoping that * really meant “add to all context menus”, but it in Microsoft world, it apparently means “add it to an unspecified subset of context menus.” Not very helpful.
So my next idea for easy access was a keyboard shortcut. I added a shortcut to the TimeToClipboard application to my desktop and bound it to the Ctrl+Alt+T keyboard combination. This works well, and works no matter what application has keyboard focus. So no matter what I’m doing, I’m never more than three keystrokes away from having a timestamp.
World changing? Hardly. But convenient. Plus the whole thing took me less than an hour to bash together and get setup, and most of that time was googling around for the names of registry keys.

No comments yet.