首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每季度更换动态壁纸目录

每季度更换动态壁纸目录
EN

Ask Ubuntu用户
提问于 2018-12-14 17:19:19
回答 3查看 1.1K关注 0票数 7

我想让我的壁纸是季节性的(夏天,秋天,冬天,春天),但也更新每日与季节性主题壁纸。

因此,本质上,我想有4个目录(summer, fall, winter, spring)。在夏天,我的壁纸背景每天都会在summer目录中的图像中旋转。然后在9月。21,壁纸目录将更改为fall,然后壁纸将逐日遍历这些图像,等等。

我很乐意写剧本,但我从哪里开始呢?

这个问题是如何唯一的

编辑:进一步澄清是什么使这个问题独特。虽然创建幻灯片的方法很多,但它们都依赖于设置图像目录。我要问的是如何动态地更改图像目录。因此,今天的幻灯片放映是从/images/winter/目录中出来的,而在春季的幻灯片放映则来自于/images/spring/目录。我可以通过在每个季度的外观设置中手动更改目录来实现这一点,但是当我可以告诉计算机为我做这件事时,我不想这样做。

EN

回答 3

Ask Ubuntu用户

发布于 2018-12-15 03:11:25

也许这是一种更简单的方法:

  1. 创建一个从~/images/mybackgrounds~/images/spring的符号链接: ln -s ~/-s/-s
  2. 使用其中一种方法显示背景幻灯片,使用来自~/images/mybackgrounds的图像。
  3. 设置crontab条目以在特定日期更改符号链接。创建一个名为~/mycrontab的文件,其内容如下:# min hr day mon道0.9 2 1 3* ln -sf ~/ -sf / -sf /-sf/spring~/-sf/-sf/-sf/图像/夏季~/图像/mybackgrounds 0 9 2 1 9* ln -sf~/-sf/-sf/-sf/fall~/-sf/mybackgrounds 0 9 21 12 *在-sf ~/映像/冬季~/图像/我的背景运行crontab ~/mycrontab来注册crontab条目。3月21日上午9点,crond将运行命令ln -sf ~/-sf/spring ~/images/mybackgrounds

从而将~/images/mybackgrounds链接到~/images/spring。6月21日上午9点,crond将更改符号链接,以便~/images/mybackgrounds指向~/images/summer。幻灯片程序被配置为从~/images/mybackgrounds中选择一个文件。~/images/mybackgrounds的路径保持不变,但现在所有内容都不同,因为符号链接指向不同的位置。9月21日和12月21日的crontab条目使用相同的技巧。

票数 2
EN

Ask Ubuntu用户

发布于 2018-12-14 17:54:35

步骤1:创建slideshow.py脚本

将其保存在一个名为~/bin/slideshow.py的文件中:

代码语言:javascript
复制
#!/usr/bin/env python
import os
import datetime as DT
import itertools as IT
import bisect
import random
import subprocess

# customize cutoffs and image_dirs however you like, but note that there must be
# the same number of items in each, and the items in cutoffs must be in sorted order.
cutoffs = [(3, 21), (6, 21), (9, 21), (12, 21)]
image_dirs = ['~/images/winter', '~/images/spring', '~/images/summer', '~/images/fall']
image_dirs = list(map(os.path.expanduser, image_dirs))

today = DT.date.today()
year = today.year

# convert the cutoffs to actual dates
cutoff_dates = [DT.date(year, m, d) for m, d in cutoffs]
# find the index into cutoff_dates where today would fit and still keep the list sorted
idx = bisect.bisect(cutoff_dates, today)
# use idx to get the corresponding image directory 
image_dir = next(IT.islice(IT.cycle(image_dirs), idx, idx+1))

# list all the files in image_dir (even in subdirectories, and following symlinks)
files = [os.path.join(root, filename)
         for root, dirs, files in os.walk(image_dirs[idx], followlinks=True)
         for filename in files]
# pick a file at random
imagefile = os.path.abspath(random.choice(files))

# find the current process's effective user id (EUID)
euid = str(os.geteuid())
# find the pid of the current EUID's gnome-session
pid = subprocess.check_output(['pgrep', '--euid', euid, 'gnome-session']).strip().decode()
# load all the environment variables of gnome-session
env = open('/proc/{}/environ'.format(pid), 'rb').read().strip(b'\x00')
env = dict([item.split(b'=', 1) for item in env.split(b'\x00')])
# get the value of DBUS_SESSION_BUS_ADDRESS environment variable
key = b'DBUS_SESSION_BUS_ADDRESS'
env = {key: env[key]}
# call gsettings to change the background to display the selected file
# with the DBUS_SESSION_BUS_ADDRESS environment variable set appropriately
subprocess.call(['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri',
                 'file://{}'.format(imagefile)], env=env)

步骤2:使其可执行:

代码语言:javascript
复制
chmod 755 ~/bin/slideshow.py

要测试事情是否按预期进行,您可以打开一个终端并重复运行slideshow.py。你应该看到背景的变化。请注意,slideshow.py根据季节的不同,在4个目录中的一个目录中查找图像,即~/images/spring~/images/summer~/images/fall~/images/winter

步骤3:配置crontab

您可以使用cron定期运行一个命令来更改背景,例如,每天一次或每分钟一次。

创建一个名为“~/mycrontab”的文件,并将类似的内容放入其中:

代码语言:javascript
复制
# min  hr     day     mon  dow
# 0      9      *       *    *    ~/bin/slideshow.py   # run once at 9AM
*      *      *       *    *    ~/bin/slideshow.py   # run once every minute

那就跑

代码语言:javascript
复制
crontab ~/mycrontab

要将更改注册到crontab,请执行以下操作。

您现在应该看到背景每分钟变化一次。(你甚至可能喜欢这样。)

crontab将忽略以#开头的行。因此,如果您希望每天更改一次背景,请取消第二行注释,将第三行注释掉,这样~/mycrontab现在看起来如下所示:

代码语言:javascript
复制
# min  hr     day     mon  dow
0      9      *       *    *    ~/bin/slideshow.py   # run once at 9AM
# *      *      *       *    *    ~/bin/slideshow.py   # run once every minute

但是,请注意,cron只在当天上午9时登录到机器上时才会运行此命令。

票数 0
EN

Ask Ubuntu用户

发布于 2023-03-20 15:06:42

好的。我的两分钱在Ubuntu 18+ (不确定以前的版本,所以这是一个免责声明)。

在Ubuntu中,可以创建一个自定义XML文件,其中包含有“持续时间”的图像路径和具有启动时间的部分。例如:

代码语言:javascript
复制
<background>
  <starttime>
    <year>2000</year>
    <month>3</month>
    <day>21</day>
    <hour>00</hour>
    <minute>00</minute>
    <second>00</second>
  </starttime>
<static>
  <duration>30.00</duration>
  <file>/home/martin/Pictures/Slideshow/spring.jpg</file>
</static>
<static>
  <duration>30.00</duration>
  <file>/home/martin/Pictures/Slideshow/summer.jpg</file>
</static>
</background>

在本例中,duration为30秒,开始日期/时间为2000年3月21日。只需添加更多具有正确持续时间的图片..。因此,计算从3月21日到6月21日的秒数,并将这个数字放在第一个<duration>部分中。然后对6月21日至9月21日也这样做,并将其放在第二个阶段。秋天和冬天等。

票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1100934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档