Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General > Member Success Stories
User Name
Password Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.


  Search this Thread
Old 12-09-2006, 07:19 PM   #1
Registered: Jan 2004
Distribution: Kubuntu 10.04 (Dell Linux-preinstalled laptop + a desktop); Maemo 5 (N900 phone computer)
Posts: 116

Rep: Reputation: 21
Auto-paste Date/Time into text apps under KDE

I have figured out a way to paste the date into the text of any application with two keypresses, in KDE. So this would apply to KUbuntu, Mandriva, SuSE, or any other linux distro using KDE. I myself am using KUbuntu Dapper (6.06).

For the longest time, I have been bugged by the lack of a way to automatically enter the current date and time into text, a sort of "timestamp", which would be really useful with something like: "Captain's log: 2006-12-09 16:16" or something. Even with the vaunted OpenOffice word processor, you can't insert the date! (There is a way to insert a code that means "current date/time", but if you type that code yesterday, and then open the file today, it will display today's date. Besides, it takes about one bazillion mouse clicks to insert that code.) I haven't found out how to do it in KWord and other applications; and besides, even if there were a way to do it in one particular application, it wouldn't apply to other applications.

The way that makes the most sense to me is to have it in Klipper, the KDE clipboard. It should be able to generate a clipboard item that's the current date/time, so that all you have to paste it into your document. And, of course, any application from browsers to word processors would have the Paste (from Clipboard) feature, right?

It took some fiddling around, but I figured out how to do it, so I wanted to share this with anyone else who might want it.

Step 1: the DCOP server

What makes this possible in KDE (I'm not sure it can be done in GNOME) is the DCOP server, an amazingly handy and brilliant way to control KDE applications from the command line. I won't get into detail about how to use DCOP, but there are a number of tutorials on the web that I will list at the end.

Suffice it to say that, if you wanted to put the string "ABCxyz" into the clipboard, you could do it with this command in a terminal:

dcop klipper klipper setClipboardContents ABCxyz

Try typing that at the command line. (Note that the word "klipper" is repeated.) Then go to some KDE application like an editor, and paste (Ctrl-V, usually). You'll see the string "ABCxyz" pasted in.

Step 2: Getting the Date

This is simple. To get the date, use the "date" command at the command line. Example:

$ date
Sat Dec 9 16:33:22 PST 2006

I like to have a more compact form for the date and time, so I add the argument "+Time now: %F %R" to the date command:

$ date "+Time now: %F %R"
Time now: 2006-12-09 16:34

(Use "date --help" to see what other formats are available.)

Step 3: Setting up a script file

We need a "program" that will put the date into the clipboard, rather than having us type the actual commands at the command line. Fortunately, this is simply a text file that we can type in. Create a file called "" by opening your favourite editor (such as Kate or KWrite) and type in the following three lines, then save:

CLIPTEXT=`date '+%F %R'`
dcop klipper klipper setClipboardContents "$CLIPTEXT"

Note the quotes carefully. After "CLIPTEXT=", there is a backquote (reverse single quote). After "date ", there is a (normal forwards) single quote. At the end of the second line, there is again a single quote, then a backquote. On the third line, those are double-quotes that surround "$CLIPTEXT". Get these wrong and you'll be totally mixed up!

After saving the file, make it executable with the command "chmod +x" (or whatever you named the file). You have to type the chmod command while in the same directory as the file.

Now, whenever you run the script program that you just typed in, the date and time will be copied to the Klipper clipboard, and you can just paste it into your application. Test it, by actually typing "" at the command line, and then pasting from clipboard to see if the date and time actually gets entered.

Step 4: Set up a hotkey that runs your script file

The last step is to add your new script to the KDE Menu. Start the KDE menu editor by right-clicking on the KDE button on the panel (usually lower left corner, just like the "Start" button in MS Windows). One of the selections is "Menu Editor", so start that. It will be as if we're adding a new program to the menu, but the program is actually the script program that you just entered,!

You'll see a tree structure that corresponds with the actual KDE Menu. Add a new menu item with
F)ile > New (I)tem. Enter some name of your choice (such as "Put date in clipboard") and maybe a description; the exact entry is not important. For the "Command:", you need to enter the name of the script program, which is "". Uncheck the "Enable launch feedback" box.

Now we define a shortcut key combination that triggers this program, which is the whole point of putting this item into the KDE Menu. (We don't actually plan to click on the KDE Menu each time to run this program!) At the bottom of the KDE Menu Editor, it says "Current Shortcut Key". Click on that box, and it will let you choose a keypress. I chose Win+1, but you can choose Alt+D or Ctrl+Shift+X or whatever.

Save the changes in the KDE Menu with F)ile > S)ave, and your system should be updated.

Now test it! Press Win+1 (or whatever shortcut key combo you selected), and then go to some editor and Ctrl-V to paste. You should get the date and time pasted!

Epilogue: You're all done!

You can vary the date format used. I have one key combo for date only, and another one for date and time.

By the way, our example script program takes up two lines (not including the first line, which is a comment). If you want to get it all onto one line, you can try the command:

date "+%F %R is the current time." | xargs -0 dcop klipper klipper setClipboardContents

I'll let you figure that one out.

The following are some web pages that have good DCOP tutorials. You can also check, which often have good tutorials on various aspects of Linux.

(I also googled for "DCOP howto", but the resulting web pages were very technical and not suitable for newbies.)

This posting is hereby licensed under the GNU Free Documentation License. I would love it if anyone pointed out errors, cleaned up the text or put in some screenshots.

Old 12-11-2011, 05:35 AM   #2
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 61

Rep: Reputation: 17
Question Ehnace usability by 100%

Good Idea! Nowadays on KDE 4
 qdbus org.kde.klipper /klipper setClipboardContents $(date  +"%Y-%m-%d_%H-%M")
does the job.

However, one thing could double usability: The need for only one but two keystrokes to insert the time stamp. Therefore, we'd need an additional command to insert the ClipboardContents into the current window (in other words, to simulate a paste action, triggered by Ctrl+v, middle mouse click or something like that).

By the way, succeeding in doing so, we even would not need to use the clipboard as detour.

On the one hand, qdbusviewer does not show up something like a paste method in "org.kde.klipper.klipper". On the other, it principally must be possible to achieve this, as applications like 'autokey' already have this functionality.

Any ideas to achieve this by means of a tiny bash or python script (which can be triggered by a custom defined hotkey or gesture in 'systemsettings')?

Last edited by devdol; 12-11-2011 at 05:38 AM.
Old 02-09-2012, 12:15 AM   #3
LQ Newbie
Registered: Feb 2012
Posts: 1

Rep: Reputation: Disabled
Why dont you simply use xdotool ?

"xdotool key ctrl+v"

or even better:

"xdotool type $(date +"%Y-%m-%d_%H-%M")"

No need to use klipper at all!

Last edited by Wattos; 02-09-2012 at 12:17 AM.
1 members found this post helpful.
Old 02-10-2012, 04:49 AM   #4
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 61

Rep: Reputation: 17
Thumbs up

Hmm, seems that some people got used to driving cars and forgot what bicycles or feet were good for ,-)

Thanks for your hint, I never knew about 'xdotool' before.
Old 02-10-2012, 08:59 AM   #5
Registered: Jan 2004
Distribution: Kubuntu 10.04 (Dell Linux-preinstalled laptop + a desktop); Maemo 5 (N900 phone computer)
Posts: 116

Original Poster
Rep: Reputation: 21
why didn't I use xdotool? the answer is simple

Why dont you simply use xdotool ?
In case you were wondering: xdotool did not exist at the time I wrote the post, twelve Ubuntu versions ago.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
suse9.3 logging out at random times gnome/kde & how to disable paste text from scroll steve.ervin21 SUSE / openSUSE 0 01-19-2006 05:07 PM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM
grub doesn't auto-load kernel, time/date auto-change, k3b cannot load kenji1903 Red Hat 16 03-27-2005 08:48 PM
auto-starting apps in kde foustware Fedora 1 11-16-2004 09:12 PM
StarOffice 6.0 beta copy/paste problem with KDE apps stodge Linux - General 1 02-14-2002 02:59 PM > Forums > Linux Forums > Linux - General > Member Success Stories

All times are GMT -5. The time now is 01:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration