使用crontab使用pcmanfm更改墙纸 [英] Changing wallpaper using pcmanfm by crontab
问题描述
我制作了一个简单的bash脚本,该脚本使用pcmanfm从我的墙纸目录更改墙纸以获取随机图片.就像这样:
I made a simple bash script that changes the wallpaper for a random picture from my wallpapers directory using pcmanfm. It's something like that:
#!/bin/bash
pcmanfm -w "$(find /home/likewise-open/MAPS/lucas.cardeal/Pictures/Wallpapers -type f | shuf -n1)"
我会自动想要它,所以您将脚本放在crontab上.但是,当crontab调用它时,它没有任何作用.我的脚本怎么了?我该如何解决?
I want that automatically, so u put the script on crontab. But it has no effect when its called by crontab. What's wrong with my script? How can I fix it?
谢谢
推荐答案
当设置为cron作业时,该脚本将给您X11授权错误.为防止这种情况,只需在脚本中添加export DISPLAY=:0
和export XAUTHORITY=/home/username/.Xauthority
(用用户名更改username
):
That script will give you a X11 authorization error when is set as cron job. To prevent this, just add export DISPLAY=:0
and export XAUTHORITY=/home/username/.Xauthority
(change username
with your user name) in your script:
#!/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/username/.Xauthority #change `username` with your user name
pcmanfm -w "$(find /home/likewise-open/MAPS/lucas.cardeal/Pictures/Wallpapers -type f | shuf -n1)"
附录:更新导致以上脚本在Lubuntu 16.04及更高版本中损坏.请参阅此stackoverflow答案 https://stackoverflow.com/a/46259031/5895207 了解需要使用的其他环境变量在脚本中指定.
ADDENDUM: An update caused the above script to break in Lubuntu 16.04 and above. See this stackoverflow answer https://stackoverflow.com/a/46259031/5895207 for the additional environment variable that needs to be specified in the script.
这篇关于使用crontab使用pcmanfm更改墙纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!