我编写了以下简单的 python 脚本,打算在 Ubuntu 12.04 中将其设置为 cron 作业,以每小时更改一次墙纸。当我从终端完美运行脚本时,该脚本会运行并更改壁纸。但是,当我设置 cron 作业时,我可以在 syslog 中看到 cron 作业已经运行但墙纸没有改变?
#!/usr/bin/python
import os
import random
directory = os.getcwd() + '/'
files = os.listdir('.')
random.shuffle(files)
files.remove('.project')
files.remove('.pydevproject')
files.remove('background.py')
background = files[0]
setup = 'file://' + directory + background
print setup
os.system("gsettings set org.gnome.desktop.background picture-uri '%s'" % (setup))