Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

Thanks.

share|improve this question

1 Answer 1

up vote 4 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
1  
@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. –  Emanuele Natale May 22 '13 at 2:26

Your Answer

 
discard

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.