Once having a unique setup running arch linux you may have the need for a high quality desktop wallpaper. For that I’ve created a script that will download once a day a desktop wallpaper as an jpg file and will store it on your file system. Then your desktop of choice can use that folder to show beautiful images as desktop wallpaper. Here’s how I did it:
#!/bin/bash
# Set the storage path
storage_path="/home/<user>/wallpapers"
# Create the storage path if it doesn't exist
mkdir -p "$storage_path"
# Define the file name
filename="$(date +'%Y-%m-%d').jpg"
# Check if the image has already been downloaded today
if [ -f "$storage_path/$filename" ]; then
echo "The Bing image has already been downloaded today."
else
# Use curl to download the Bing image
image_url=$(curl -s "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1" | jq -r '.images[0].url')
curl -s "https://www.bing.com/$image_url" -o "$storage_path/$filename"
echo "The Bing image has been successfully downloaded and saved to $storage_path/$filename."
fi
In the script you need to replace <user> with the name of your user.
Make sure you have the jq
tool installed as it’s used to extract the image URL from Bing’s JSON response. You can install it on most Linux distributions using sudo apt install jq
or sudo yum install jq
, depending on your package manager.
Save this script in a file, for example, bing_daily_wallpaper.sh
, and execute it. You can also set up a cron job to ensure it runs automatically once a day. Use the crontab -e
command to edit your cron job schedule. Then, add a line like this to run the script every day:
0 0 * * * /bin/bash /path/to/your/bing_daily_wallpaper.sh
Replace /path/to/your/
with the actual path to your script. This will execute the script daily at midnight and download the current Bing image.