我制作了一个简单的 bash 脚本,它使用 pcmanfm 从我的墙纸目录中为随机图片更改墙纸。是这样的:
#!/bin/bash
pcmanfm -w "$(find /home/likewise-open/MAPS/lucas.cardeal/Pictures/Wallpapers -type f | shuf -n1)"
我想自动执行,所以你把脚本放在 crontab 上。但是当它被crontab调用时,它没有任何效果。我的脚本有什么问题?我该如何解决?
谢谢
最佳答案
当设置为 cron 作业时,该脚本会给你一个 X11 授权错误。为了防止这种情况,只需添加 export DISPLAY=:0
和 export XAUTHORITY=/home/<em>username</em>/.Xauthority
(将 <em>username</em>
更改为您的用户名)在您的脚本中:
#!/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/<em>username</em>/.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对于需要在脚本中指定的附加环境变量。
关于bash - 通过 crontab 使用 pcmanfm 更改壁纸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19660345/