Bing’s “Image of the Day” often features stunning and inspiring images from around the world, making it a perfect choice for your desktop wallpaper. In this guide, we’ll walk you through a simple Bash script that automatically downloads the Bing image of the day in the highest quality and saves it with a filename that includes the image’s title, location, and date. We’ll also cover how to set this image as your wallpaper in Linux (Hyprland), Windows, and macOS.

The Bash Script

Below is a Bash script that you can use to download the Bing image of the day:

#!/bin/bash

# Target directory where the image will be saved
target_dir="/home/johannes/wallpaper"

# Create the target directory if it doesn't exist
mkdir -p "$target_dir"

# API URL for Bing's Image of the Day (for Germany, change "mkt" for other regions)
api_url="https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=de-DE"

# Fetch the JSON data from Bing's server
json_data=$(curl -s "$api_url")

# Extract the image URL, title, and location from the JSON data
image_url="https://www.bing.com$(echo $json_data | grep -oP '(?<="url":")[^"]*')"
title=$(echo $json_data | grep -oP '(?<="title":")[^"]*')
location=$(echo $json_data | grep -oP '(?<="copyright":")[^,]*' | sed 's/^[^()]* (\([^)]*\)).*$/\1/')

# Extract the date (the day the image is shown)
date=$(date +%Y-%m-%d)

# Create the filename: Title + Location + Date
filename="${title// /_}_${location// /_}_$date.jpg"

# Full path for saving the image
filepath="$target_dir/$filename"

# Download the image in maximum resolution (UHD)
curl -s -o "$filepath" "$image_url&rf=LaDigue_UHD.jpg"

echo "Image of the Day downloaded as $filepath"

How the Script Works

  • Target Directory: The script sets the directory where the image will be saved. In this case, it’s /home/johannes/wallpaper, but you can change it to any directory you prefer.
  • Create Directory: The script checks if the target directory exists and creates it if it doesn’t. This ensures that the script won’t fail if the directory isn’t already there.
  • API URL: The script accesses the Bing API to get the JSON data that includes information about the image of the day. The mkt=de-DE parameter specifies the region (Germany in this case). You can change this to your preferred region (e.g., en-US for the United States).
  • Extracting Data: The script extracts the image URL, title, and location from the JSON data using grep and sed. The title and location are used to create a descriptive filename.
  • Filename Creation: The script generates a filename that includes the title, location, and date, replacing spaces with underscores to make it filesystem-friendly.
  • Image Download: Finally, the script downloads the image in its highest available resolution (UHD) and saves it to the specified directory with the generated filename.

Setting the Image as Your Wallpaper

Once you’ve downloaded the image, the next step is to set it as your desktop wallpaper. Below are instructions for doing this on Linux (Hyprland), Windows, and macOS.

Linux (Hyprland)

Hyprland is a dynamic tiling Wayland compositor. To set the wallpaper in Hyprland, you’ll typically need a helper application like swaybg or hyprpaper.

  1. Install hyprpaper (if not already installed):
   sudo pacman -S hyprpaper
  1. Set the wallpaper:
   hyprpaper set /home/johannes/wallpaper/your_downloaded_image.jpg

Add the hyprpaper command to your Hyprland config file (usually located at ~/.config/hypr/hyprland.conf) to ensure the wallpaper is set on startup.

Windows

In Windows, setting the image as your wallpaper can be done via a script or manually:

  1. Manually:
  • Right-click on the desktop and select “Personalize.”
  • Choose “Browse” under the “Background” section and select the downloaded image.
  1. Via PowerShell:
    You can also set the wallpaper using PowerShell:
   $path = "C:\Users\YourUsername\wallpaper\your_downloaded_image.jpg"
   Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;public class Wallpaper{[DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); public static void SetWallpaper(string path) { SystemParametersInfo(20, 0, path, 0x01 | 0x02); }}'
   [Wallpaper]::SetWallpaper($path)

macOS

On macOS, you can set the wallpaper either manually or via a terminal command:

  1. Manually:
  • Open System Preferences -> Desktop & Screen Saver.
  • Click the “+” button to add the downloaded image folder and select the image.
  1. Via Terminal:
   osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/YourUsername/wallpaper/your_downloaded_image.jpg"'

Conclusion

With this Bash script, you can automatically download Bing’s stunning image of the day, save it with a descriptive filename, and set it as your wallpaper on any major operating system. Whether you’re using Linux, Windows, or macOS, you can easily keep your desktop fresh and inspiring with beautiful images from around the world.

Downloading the Bing Image of the Day for Your Wallpaper in Linux, Windows, and macOS

Johannes Rest


.NET Architekt und Entwickler


Beitragsnavigation


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert