我目前正在参加一个学习项目。我们被要求下载一张特定的图片,然后将其用作壁纸,通过命令行进行操作。给出的指示没有任何效果:
首先我们必须下载一张图片,然后我们将使用命令将其作为背景。
$ wget -O ~/Downloads/wallpaper.jpg "https://raw.githubusercontent.com/hoppersroppers/hoppersroppers.github.io/main/_layouts/constitution.jpg"
$ gsettings set org.gnome.desktop.background picture-uri file:////tmp/wallpaper.jpg
现在您的背景图片应该是一张船的图片!如果不起作用,请排除故障。
https://www.baeldung.com/linux/change-desktop-wallpaper-from-terminal 主要是因为 C/P 给定的命令没有产生任何变化。我认为这是一个“测试”。我不明白为什么如果图像在下载中,它会指向 tmp?
ob@adminbaby:~/Desktop$ wmctrl -m
Name: GNOME Shell
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF
bob@adminbaby:~/Desktop$ gsettings set org.gnome.desktop.background picture-uri file:////tmp/wallpaper.jpg
bob@adminbaby:~/Desktop$ pwd
/home/bob/Desktop
bob@adminbaby:~/Desktop$ ls
first
bob@adminbaby:~/Desktop$ sudo gsettings set org.gnome.desktop.background picture-uri file:////tmp/wallpaper.jpg
[sudo] password for bob:
(process:2230): dconf-WARNING **: 16:39:33.016: failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory)
bob@adminbaby:~/Desktop$ gsettings set org.gnome.desktop.background picture-uri file://// ~/Downloads/wallpaper.jpg
Usage:
gsettings [--schemadir SCHEMADIR] set SCHEMA[:PATH] KEY VALUE
Set the value of KEY to VALUE
Arguments:
SCHEMADIR A directory to search for additional schemas
SCHEMA The name of the schema
PATH The path, for relocatable schemas
KEY The key within the schema
VALUE The value to set
bob@adminbaby:~/Desktop$ sudo gsettings set org.gnome.desktop.background picture-uri file:////home/bob/Downloads.jpg
(process:2240): dconf-WARNING **: 16:40:57.446: failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory)
bob@adminbaby:~/Desktop$ gsettings set org.gnome.desktop.background picture-uri file:////home/bob/Downloads/wallpaper.jpg
bob@adminbaby:~/Desktop$ sudo gsettings set org.gnome.desktop.background picture-uri file:////tmp/wallpaper.jpg
bob@adminbaby:~/Desktop$ wmctrl -m
Command 'wmctrl' not found, but can be installed with:
sudo apt install wmctrl
bob@adminbaby:~/Desktop$ sudo apt install wmctrl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
wmctrl
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 20.6 kB of archives.
After this operation, 63.5 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu lunar/universe amd64 wmctrl amd64 1.07-7ubuntu1 [20.6 kB]
Fetched 20.6 kB in 0s (62.8 kB/s)
Selecting previously unselected package wmctrl.
(Reading database ... 203962 files and directories currently installed.)
Preparing to unpack .../wmctrl_1.07-7ubuntu1_amd64.deb ...
Unpacking wmctrl (1.07-7ubuntu1) ...
Setting up wmctrl (1.07-7ubuntu1) ...
Processing triggers for man-db (2.11.2-1) ...
bob@adminbaby:~/Desktop$ wmctrl -m
Name: GNOME Shell
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF
bob@adminbaby:~/Desktop$ realpath -s wallpaper.jpg
/home/bob/Desktop/wallpaper.jpg
bob@adminbaby:~/Desktop$ sudo gsettings set org.gnome.desktop.background picture-uri file://///home/bob/Desktop/wallpaper.jpg
(process:2829): dconf-WARNING **: 16:53:30.948: failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory)
bob@adminbaby:~/Desktop$ gsettings set org.gnome.desktop.background picture-uri file:///home/bob/Downloads/wallpaper.jpg
bob@adminbaby:~/Desktop$
bob@adminbaby:~/Desktop$ realpath -s wallpaper.jpg
/home/bob/Desktop/wallpaper.jpg
bob@adminbaby:~/Desktop$ sudo gsettings set org.gnome.desktop.background picture-uri file://///home/bob/Desktop/wallpaper.jpg
(process:2829): dconf-WARNING **: 16:53:30.948: failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory)
bob@adminbaby:~/Desktop$
答案1
您使用了正确的命令来更改壁纸。除非您不需要使用sudo
withgsettings
命令。以下命令将下载并更改桌面背景。
wget -O ~/Downloads/wallpaper.jpg "https://raw.githubusercontent.com/hoppersroppers/hoppersroppers.github.io/main/_layouts/constitution.jpg"
gsettings set org.gnome.desktop.background picture-uri file:///$HOME/Downloads/wallpaper.jpg # $HOME will expand to /home/bob
此处讨论了类似的问题gsettings 命令行工具不会更改背景。