1

Is there any way I can clear the X clipboard from a cron job? The usual commands for xclip don't seem to work.

echo -n | xclip -selection clipboard

doesn't work from cron.

Tao W
  • 11

1 Answers1

2

X programs use DISPLAYs to work out what X11 instance to apply the program to. If you are the sole user of your host then most likely your display will be localhost:0 or often abbreviated to :0. you can find your DISPLAY variable by using:

echo ${DISPLAY}

To tell xclip to use that display, issue the -display command line option, or set the the DISPLAY environment variable

echo -n | xclip -display :0 -selection clipboard
Drav Sloan
  • 14,345
  • 4
  • 45
  • 43
  • A good answer, except that the default display is usually :0, and trying to use :1 will result in an error. – larsks Aug 04 '15 at 12:31
  • Bad habbits! (I always have two X sessions, one is a VNC instance, and the other I rarely use). I should know better! I will update - thanks! – Drav Sloan Aug 04 '15 at 12:34