Insert Date

I wanted a hotkey to insert the current date at the cursor in ALL programs. Turns out this is rather tricky, because there is (of course) no common API to “insert text” in all X programs (open standards means you can get it to work with slightly less Perl than proprietary standards. Or more Perl and less wireshark).

The best solution (not so great) I have so far is to use xmacro. The input to xmacro would look something like this:

Delay 1
String 2006-03-27

Where “Delay 1” gives you 1 second to take your fingers off the keys.

So a handy script can generate this macro for any desired string:

#!/bin/bash

echo Delay 1
while read line ; do
        echo "String $line"
done

Then a handy script can feed it into xmacroplay:

#!/bin/sh

type-gen-macro | xmacroplay $DISPLAY

And a shortcut can be assigned to

date +'%F' | xtype

Hacky and slow, but it works.

Advertisements
This entry was posted in X. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s