Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While editing text documents I need to put time stamps frequently. I thought of automating it in 2 different ways. None of these seem to be working.

  1. Using nautilus-actions

I set up a new right-context action which runs the command date|xclip

enter image description here

This right-context doesn't show up when I right click in other applications (such as terminal, or browser). Moreover when it appears, and I click on it, it doesn't do anything.

  1. Using keyboard shortcut

I setup a new keyboard shortcut which is supposed to execute date command but doesn't.

enter image description here

Any pointers?


share|improve this question
up vote 8 down vote accepted

GNOME keyboard shortcuts should work.

Here's why what you tried didn't work: Your keyboard shortcut runs the date command, but does nothing with the output (which just gets discarded). You should pipe it to xclip, as date | xclip to copy it to the X selection (not clipboard). Then you can paste it into your document by middle-clicking. If you want to be able to use Ctrl-V, instead use date | xclip -selection c to copy it to the actual clipboard.

Another alternative is to use xdotool to type the date directly into your document. Assign to your shortcut

xdotool type "$(date)"

Then, when you press the shortcut key, it will calculate the current date and type the characters it into your document.

For ISO 8601 format, use xdotool type "$(date --rfc-3339=s)".

If it doesn't work: Because these are shell commands (as opposed to executables), you might have to pass the command to bash when specifying them in your shortcut. Your command would then be:

bash -c 'xdotool type "$(date --rfc-3339=s)"'
share|improve this answer
Thanks. Tried it. But it's not working. I assigned the shortcut to CTRL+; and I click this particular combination on desktop and then I click CTRL+V (say in gmail) but it doesn't paste. Do I have to restart laptop? – user13107 Jan 7 '13 at 7:02
@user13107: It turns out that by default, xclip copies the text not to the clipboard, but to the X selection. To paste it, use middle-click rather than Ctrl-V. – Mechanical snail Jan 7 '13 at 7:11
Using bash -c did the trick but there is some kind of delay in typing. When I click the shortcut, complete timestamp is not typed using xdotool. Some initial numbers are eaten up e.g. 1-07 15:14:35+08:00or 013-01-07 15:14:35+08:00 – user13107 Jan 7 '13 at 7:16
Yes, the {xclip, middle-click} solution works! But it still needs me to click twice. One for keyword shortcut, another for middle-click. I don't know why xdotool seems to give glitches. Thanks, anyways! – user13107 Jan 7 '13 at 7:24
@user13107 I had the same issue. After some trial and error I ended up with the command bash -c 'date | xclip -selection clipboard && xdotool key 'ctrl+v'' that works perfectly. – Immanuel Weihnacht May 22 '13 at 2:26

I've been successfully using this as a custom keyboard shortcut assigned to Ctrl+Shift+D:

bash -c 'sleep 0.3 && xdotool type "$(date -u +%Y-%m-%d_%H:%M:%SZ)"'

I found adding a slight delay solved the issues with missing initial characters, and doesn't pollute my clipboard.

Note that I'm using a slightly customized version of RFC 3339/ISO 8601 format: I often use this in contexts where I want to avoid the space in date's RFC 3339 output, but I find the T that separates the date from the time in ISO 8601 timestamps rather unintuitive and difficult to read, so I find an underscore works well.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.