Qual é o problema com este script para mudar o papel de parede?

2

Sou muito novo no mundo do Linux, por isso peço que me perdoe por cada coisa estúpida ou simples que vou pedir agora.

Eu instalei o Elementary OS no site deles ontem. Eu queria mudar meu papel de parede automaticamente com o papel de parede do Bing, então achei no Google um script que baixa dos servidores do Bing a imagem ... Isso é bom, funciona (vejo as imagens baixadas dentro da pasta).

O problema é que nem sempre muda o papel de parede. Às vezes sim, às vezes não. Eu não entendo realmente quando e por quê. Parece que acontece quando a imagem baixada não é nova. Desculpem pelo meu Inglês ruim, o que quero dizer é que eu coloquei esse script começando na inicialização com a ferramenta fornecida com o Elementary OS, e se eu ligo meu pc > 1 vez por dia, (e a imagem do Bing muda uma vez por dia) as outras vezes eu só pego tudo preto como papel de parede. Aqui está a parte do código que muda de papel de parede, talvez esteja lá o problema:

#!/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
    
por Francesco Bonizzi 07.10.2013 / 18:08

1 resposta

3

Em vez de mexer com dconf , você pode usar feh --bg-max para definir a imagem de fundo com bastante facilidade.

$ feh --bg-max <image>

Eu uso esse tipo de script para girar a imagem de fundo a cada 15 minutos, por exemplo:

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

O acima também usa o comando shuf pouco usado, mas prático, para randomizar uma lista de arquivos.

    
por 07.10.2013 / 20:37