How to create option to insert time stamp?
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.
- Using nautilus-actions
I set up a new right-context action which runs the command date|xclip
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.
- Using keyboard shortcut
I setup a new keyboard shortcut which is supposed to execute date
command but doesn't.
Any pointers?
Thanks.
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)"'
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.
bash -c 'xdotool keyup super && xdotool type "$(date +%Y.%m.%d)"'
I use Super+Q
as my shortcut, and I need to clear the super
modifier before sending the date
. I tried --clearmodifiers
but that would cause the unity dash
to pop up after the shortcut is run [1]
[1] The reason unity dash
would pop up afterward is before the super
is restored if --clearmodifiers
is used
Quote from man xdotool
CLEARMODIFIERS
Any command taking the --clearmodifiers flag will attempt to clear any
active input modifiers during the command and restore them afterwards.