【问题标题】:How to change desktop background in Linux using Cron [closed]如何使用 Cron 在 Linux 中更改桌面背景 [关闭]
【发布时间】:2019-01-07 13:41:28
【问题描述】:

我找到了更改桌面壁纸的终端命令:

gsettings set org.gnome.desktop.background picture-uri file:///path/to/your/image.png

但此命令在 cron 和其他桌面(如 Mate)中不起作用。 pgrep gnome-session 方法对我没有任何帮助。

【问题讨论】:

  • 我投票决定将此问题作为离题结束,因为有关 Linux 的问题属于 unix.stackexchange.com 如果您确实在那里问这个问题,请在此处删除。
  • 我投票反对关闭它 - 努力回答问题,而不是将用户重定向到其他页面。
  • Gsettings with cron的可能重复
  • @jww,这个关于 bash (shell) 编程和开发跨发行版脚本的问题

标签: linux terminal cron command-line-interface wallpaper


【解决方案1】:

您可以使用dconf 更改背景。以下是简单 bash 脚本的示例:

#!/bin/bash

WP="$(find ~+ -type f -exec mimetype {} + 2>/dev/null | awk -F': +' '{ if ($2 ~ /^image\//) print $1 }' | sort -R | tail -30 | shuf -n 1)"

dconf write /org/mate/desktop/background/picture-filename "'${WP}'"

您可以使用 GUI 应用程序找到发行版特定的密钥 - dconf-editor

但要在 CRON 中使用此脚本,您需要设置会话环境变量。命令pgrep gnome-session 在 Mint 和其他非 Gnome 桌面中不起作用。要解决这个问题,需要在系统启动时运行命令保存特定用户的环境变量:

env > ~/cronenv && sed -i '/%s/d' ~/cronenv

现在您在用户主目录中有cronenv 文件(没有替代变量 - %s)。在运行dconf之前将它们恢复到cron中:

*/1 7-21 * * * cd ~/Pictures && env $(cat ~/cronenv | xargs) /path/to/first/script

使用 crontab -e 为当前用户编辑 cron 作业。一切正常!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 2021-12-21
    • 2015-10-04
    • 1970-01-01
    相关资源
    最近更新 更多