배경 화면을 변경하는 이 스크립트의 문제점은 무엇입니까?

배경 화면을 변경하는 이 스크립트의 문제점은 무엇입니까?

나는 리눅스 세계에 대해 아주 처음 접했기 때문에 지금 물어볼 모든 어리 석고 너무 단순한 것에 대해 용서를 구하고 싶습니다.

어제 웹사이트에서 Elementary OS를 설치했습니다. 내 배경화면을 Bing의 배경화면으로 자동으로 변경하고 싶었기 때문에 Bing의 서버에서 이미지를 다운로드하는 스크립트를 Google에서 찾았습니다... 좋습니다. 작동합니다(폴더 안에 다운로드된 이미지가 보입니다).

문제는 배경화면이 항상 바뀌지는 않는다는 것입니다. 때로는 그렇습니다. 때로는 그렇지 않습니다. 나는 정말로 언제, 왜 그런지 이해하지 못합니다. 다운로드한 이미지가 새로운 것이 아닐 때 발생하는 것 같습니다. 영어가 서툴러서 죄송합니다. 즉, Elementary OS에 제공된 도구를 사용하여 부팅 시 이 스크립트를 시작하고 PC를 하루에 1회 이상 켜면(그리고 Bing의 이미지는 하루에 한 번씩 변경됩니다) 다른 때에는 배경화면으로 모든 것을 검은색으로 설정합니다. 배경 화면을 변경하는 코드 부분은 다음과 같습니다. 아마도 문제가 있을 수 있습니다.

#!/bin/bash

# $bing is needed to form the fully qualified URL for
# the Bing pic of the day
bing="www.bing.com"

# $xmlURL is needed to get the xml data from which
# the relative URL for the Bing pic of the day is extracted
#
# The mkt parameter determines which Bing market you would like to
# obtain your images from.
# Valid values are: en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ, en-CA.
#
# The idx parameter determines where to start from. 0 is the current day,
# 1 the previous day, etc.
xmlURL="http://www.bing.com/HPImageArchive.aspx?format=xml&idx=1&n=1&mkt=en-US"

# $saveDir is used to set the location where Bing pics of the day
# are stored.  $HOME holds the path of the current user's home directory
saveDir=$HOME'/Pictures/BingDesktopImages/'

# Create saveDir if it does not already exist
mkdir -p $saveDir

# Set picture options
# Valid options are: none,wallpaper,centered,scaled,stretched,zoom,spanned
picOpts="zoom"

# The desired Bing picture resolution to download
# Valid options: "_1024x768" "_1280x720" "_1366x768" "_1920x1200"
desiredPicRes="_1366x768"

# The file extension for the Bing pic
picExt=".jpg"

# Extract the relative URL of the Bing pic of the day from
# the XML data retrieved from xmlURL, form the fully qualified
# URL for the pic of the day, and store it in $picURL

# Form the URL for the desired pic resolution
desiredPicURL=$bing$(echo $(curl -s $xmlURL) | grep -oP "<urlBase>(.*)</urlBase>" | cut -d ">" -f 2 | cut -d "<" -f 1)$desiredPicRes$picExt

# Form the URL for the default pic resolution
defaultPicURL=$bing$(echo $(curl -s $xmlURL) | grep -oP "<url>(.*)</url>" | cut -d ">" -f 2 | cut -d "<" -f 1)

# $picName contains the filename of the Bing pic of the day

# Attempt to download the desired image resolution. If it doesn't
# exist then download the default image resolution
if wget --quiet --spider "$desiredPicURL"
then

    # Set picName to the desired picName
    picName=${desiredPicURL##*/}
    # Download the Bing pic of the day at desired resolution
    curl -s -o $saveDir$picName $desiredPicURL
else
    # Set picName to the default picName
    picName=${defaultPicURL##*/}
    # Download the Bing pic of the day at default resolution
    curl -s -o $saveDir$picName $defaultPicURL
fi

# Set the GNOME3 wallpaper
DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-uri '"file://'$saveDir$picName'"'

# Set the GNOME 3 wallpaper picture options
DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-options $picOpts

 # Remove pictures older than 30 days
find $saveDir -atime 30 -delete

# Exit the script
exit

답변1

혼란스러워하는 대신 배경 이미지를 상당히 쉽게 설정할 dconf수 있습니다 .feh --bg-max

$ feh --bg-max <image>

저는 이 유형의 스크립트를 사용하여 15분마다 배경 이미지를 회전합니다. 예를 들면 다음과 같습니다.

while true; do
  find ~/.wallpaper -type f \( -name '*.jpg' -o -name '*.png' \) -print0 |
    shuf -n1 -z | xargs -0 feh --bg-max
    sleep 15m
done

shuf위의 내용은 파일 목록을 무작위로 지정하기 위해 거의 사용되지 않지만 편리한 명령을 사용합니다 .

관련 정보