Register
It is currently Wed Dec 13, 2017 10:59 am

Paste Current Date to Clipboard


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed Jul 20, 2016 5:08 pm   

Joined: Wed Jul 20, 2016 4:32 pm
Posts: 2
Hello . . .

First post. Be gentle.

I just upgraded to KDE Neon 5.7.2 from Kubuntu 14.04 and one of my necessary options is not implemented or not yet implemented. In Kubuntu 14.04, right clicking on the digital clock gave me an option titled, "Copy to clipboard". Neon does not have that option. I use the current date many, many times a day and this option in a submenu allowed me to paste the current date in the proper format in a document. I miss it!

I have tried through a Bash script to reproduce the action but I have failed miserably. All my searching suggests that in the script I should use xclip or xsel. At best xclip only sends the first word (up to a space?) to the clipboard and then I cannot paste it anywhere. I see it in the clipboards contents but it doesn't come out. I don't know if the number of clipboards in Linux is at fault.

I have tried,
echo date `+%A %d %B %Y` | xclip -i
echo date `+%A, %d %B %Y` | xclip -d
echo `date +%y%m%d` && xclip
date `+%y%m%d` | xclip
sDATE=`date +%y%m%d` | xclip $sDATE
and a few more variations that my keyboard buffer has lost.

I have gone through the man pages for xclip, Bash and xclip and the above is the best that I have come up with to solve my problem.

Is what I want possible?

Thank You

pmb


Top
 Profile  
 PostPosted: Thu Jul 21, 2016 7:51 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
Modern Unices use DBus for InterProcessCommunication.
So does KDE.
The part implementing the clipboard is named klipper.

There are two programs to inspect DBus. qdusviewer is the GUI program, qdbus is the CLI counterpart.

Code:
qdbus   # gives a lot of information on running dbus capable programs
# we do know that we want klipper
qdbus  | grep klipper
# and get back the real name of klipper in DBus.
qdbus org.kde.klipper   # shows us public interfaces of klipper
qdbus org.kde.klipper /klipper  # shows the available functions
# so we use setClipboardContents
qdbus org.kde.klipper /klipper setClipboardContents  "$(date +"create wanted date string: %Y %m %d")"


Of course you can use xclip too, if using proper syntax:
Code:
date |  xclip


Top
 Profile  
 PostPosted: Thu Jul 21, 2016 8:04 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
pmb wrote:
echo date `+%A %d %B %Y` | xclip -i
echo date `+%A, %d %B %Y` | xclip -d
echo `date +%y%m%d` && xclip
date `+%y%m%d` | xclip
sDATE=`date +%y%m%d` | xclip $sDATE


All the above commands doing different things, but not, what you intend.
echo date `+%A %d %B %Y` | xclip -i this tries to execute a command named +%A %d %B %Y which does not exist.
There are two forms bash can execute commands $( somecommand) and the old posix way ` somecommand `.
You want to quote it. There are double- and single quotes: " double quoted string - bash will expand $something " or ' single quoted string and bash cannot expand $somevar - $somevar will be printed literally. '

echo date is a useless pattern, as date already prints something.

sDATE=`date +%y%m%d` | xclip $sDATE This is split into two steps. The correct form of this is: my_date=` date +%y... ` ; echo $my_date | xclip


Top
 Profile  
 PostPosted: Thu Jul 21, 2016 9:44 am   

Joined: Wed Jul 20, 2016 4:32 pm
Posts: 2
uhelp Thank You for the reply

You have shown me the error of my ways and given me two ideas for a solution. Both look promising.

Thank You again


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP