Linux Mint 13 を xfce で実行しています。このスレッドのスクリプトを使用して、次の形式で cronjob を実行することができました。
PATH=/usr/bin/python/:/usr/bin/python3/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# The Wallpaper Changer
0 * * * * /home/tessitura/8BitDay/set.py
...しかし、スクリプト自体に問題が発生しています。そのまま、ディレクトリ名だけを変更すると、次のエラーが表示されます。
Traceback (most recent call last):
File "./set.py", line 19, in <module>
os.rename('now.png', current)
OSError: [Errno 2] No such file or directory
コードを少し調整してみましたが、うまくいきました。壁紙は変更されますが、now.pngが削除されてしまい、cron ジョブを実行すると空白の画像が表示されます。これが私が今持っているものです:
#!/usr/bin/python3
# Finds the current hour
import datetime
time = int(str(datetime.datetime.now().time()).split(":")[0])
# Needed for renaming files
import os
# List of all files in the folder
files = ['05-Evening.png', 'set.py', '07-Night.png', '01-Morning.png', '03-Afternoon.png', '06-Late-Evening.png', '08-Late-Night.png', '04-Late-Afternoon.png', '02-Late-Morning.png', 'now.png']
# Finds which wallpaper is currently set
directory = "/home/tessitura/8BitDay/"
for filename in os.listdir(directory):
files.remove(files[files.index(filename)])
current = ''.join(filename)
# Puts back the current wallpaper
path = os.path.join(directory, 'now.png')
os.rename(path, current)
# Gets out the new wallpaper based on time
if 0 <= time <= 3:
os.rename('08-Late-Night.png', 'now.png')
elif 4 <= time <= 5:
os.rename('01-Morning.png', 'now.png')
elif 6 <= time <= 10:
os.rename('02-Late-Morning.png', 'now.png')
elif 11 <= time <= 14:
os.rename('03-Afternoon.png', 'now.png')
elif 15 <= time <= 16:
os.rename('04-Late-Afternoon.png', 'now.png')
elif 17 <= time <= 18:
os.rename('06-Late-Evening.png', 'now.png')
elif 19 <= time <= 23:
os.rename('07-Night.png', 'now.png')
# Refreshes the desktop
os.system("xfdesktop --reload")
更新: Blckknght のソリューションはスクリプトを修正します。Mint 13 ではすべて問題ありませんが、Mint 17.1 にアップグレードしたところ、再び問題が発生しました。スクリプトはスタンドアロンで問題なく動作しますが、今回の問題は crontab にあります。1 時間ごとに cronjob を実行すると、次のようになります。
Failed to parse arguments: Cannot open display:
cronjobをこれに変更しました...
PATH=/usr/bin/python/:/usr/bin/python3/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@hourly DISPLAY=:0.0 /home/tessitura/8BitDay/set.py > /home/tessitura/set.log 2>&1
これは私にこのエラーを与えます:
Failed to connect to session manager: Failed to connect to the session manager: SESSION_MANAGER environment variable not defined
** (xfdesktop:9739): WARNING **: xfdesktop: already running, quitting.