
所以,我有个主意。为了让我更好地了解星期几,我想为每一天定制一张壁纸。但我不知道如何实现这一点。
有没有软件可以帮我实现这个功能?如果没有,有人能帮我设置一个可以每天更改背景的脚本吗?
答案1
按照此示例创建一个脚本,名为dailywallpaper.sh
:
#!/bin/bash
# Variables explained:
# [wallpaperpath]....The directory with your wallpapers.
# [background].......The wallpaper. For the current "Week" day make a symbolic
# link to the desired image. Name the line the a number
# between 1-7 with a dash and the name without extension.
# (ie. ln -s image.png 3-daily for the thrird day of the
# week)
# [default]..........The default wallpaper to set if the file matching the
# current day isn't found.
DBUS=$(ps aux | egrep "/gnome-session/.*\s--session=" | awk '{print $2}')
export $(strings /proc/$DBUS/environ | egrep DBUS_SESSION_BUS_ADDRESS)
day=$(date +"%u")
wallpaperpath="/home/userid/backgrounds/"
background="$day-daily"
default="manhattan-wallpaper-2.jpg"
# Default when the specified file isn't found.
newwallpaper="$wallpaperpath$default"
[[ -f "$wallpaperpath$background" ]] && newwallpaper="$wallpaperpath$background"
gsettings set org.gnome.desktop.background picture-uri "file://${newwallpaper}"
脚本的注释中解释了脚本的用法。您可以通过 设置脚本运行crontab
。
Crontab 示例条目:
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
0 0 * * * /home/myaccount/bin/dailywallpaper.sh
启动应用程序应用程序如果您在午夜时未登录,则需要。启动应用程序将在您登录时进行更改。您可以在 Ubuntu Dash 中找到启动应用程序:(Ubuntu Dash -> Startup Applications
)。
crontab
如果您已登录,该条目将设置后台变量。Startup Applications
如果您在 cron 运行时午夜未登录,应用程序将设置该变量。
使用这两个,总是会显示正确日期的壁纸。
答案2
我会使用自行车壁纸:
然后我将使用 conky 来显示星期几:
来自这个网站:https://ubuntuforums.org/showthread.php?t=281865&page=2325&p=13554728#post13554728
还有这张照片:https://ubuntuforums.org/attachment.php?attachmentid=264010
让 ConkyMONDAY
以大写字母显示非常容易。查看网站并找到赏心悦目的脚本,然后对其进行更改以满足您的需求。
答案3
从 cron 设置壁纸
从 cron 设置壁纸需要设置gsettings
。由于cron
运行时环境变量非常有限,因此您需要设置一个特殊变量,称为:
DBUS_SESSION_BUS_ADDRESS
不是(您所期望的)DISPLAY
变量。
另请参阅这里怎么做。
或者
或者,您可以使用下面的简单脚本。启动时,脚本会设置相应的壁纸,然后脚本所做的就是等到午夜,然后更改壁纸。然后再次休眠直到下一个午夜,依此类推。
剧本
import time
import os
import subprocess
picsdir = "/home/jacob/Bureaublad/pics"
images = sorted([os.path.join(picsdir, pic) for pic in os.listdir(picsdir)])
def calc_sleep():
secdata = time.strftime("%H %M %S").split()
seconds = (int(secdata[0])*3600)+(int(secdata[1])*60)+(int(secdata[2]))
# calculate the sleep time until next midnight
return 86400+1-seconds
while True:
# weekday
day = int(time.strftime("%w"))
# the corresponding image from the set folder
image = images[day-1]
# set the image from gsettings
command = ["gsettings", "set", "org.gnome.desktop.background",
"picture-uri", "file://"+image]
subprocess.check_call(command)
# calculate the time to sleep until next midnight
wait = calc_sleep()
time.sleep(wait)
如何使用
- 创建一个包含七张壁纸的目录
- 将脚本复制到一个空文件中,另存为
wallswitch.py
- 在脚本的头部,设置壁纸的路径
测试运行脚本:
python3 /path/to/wallswitch.py
应该设置与星期几相对应的壁纸。
如果一切正常,请将其添加到启动应用程序:Dash > 启动应用程序 > 添加。添加命令:
/bin/bash -c "sleep 10 && python3 /path/to/wallswitch.py"