Skip to content

Instantly share code, notes, and snippets.

@coreequip
Created October 10, 2025 14:15
Show Gist options
  • Save coreequip/49bad693be8d21419a1fed00a99cb1dd to your computer and use it in GitHub Desktop.
Save coreequip/49bad693be8d21419a1fed00a99cb1dd to your computer and use it in GitHub Desktop.
MacOS-Shell script for changing wallpaper to BING® Picture of the day.

BING® Picture of the day

This is a MacOS shell script for changing wallpaper to BING® Picture of the day.

Place the shell script into: ~/Pictures/Bing and the plist into ~/Library/LaunchAgents/.

Run once:

launchd load ~/Library/LaunchAgents/com.user.bing-wallpaper.plist

Manual test it:

launchctl start com.user.bing-wallpaper
#!/bin/bash
API_URL="https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"
BASE_DIR="$HOME/Pictures/Bing"
UHD_DIR="$BASE_DIR/UHD"
PORTRAIT_DIR="$BASE_DIR/Portrait"
INFO_FILE="$BASE_DIR/info.txt"
TEMP_DIR="/tmp/bing_wallpaper_$$"
RED='\033[0;31m'
NC='\033[0m'
set -e
trap 'rm -rf "$TEMP_DIR"' EXIT
mkdir -p "$UHD_DIR" "$PORTRAIT_DIR" "$TEMP_DIR"
json_data=$(curl -s "$API_URL")
urlbase=$(echo "$json_data" | grep -o '"urlbase":"[^"]*"' | head -1 | cut -d'"' -f4)
copyright=$(echo "$json_data" | grep -o '"copyright":"[^"]*"' | head -1 | cut -d'"' -f4)
filename=$(echo "$urlbase" | sed -n 's/.*OHR\.\(.*\)_DE-.*/\1/p')
if [ -z "$filename" ]; then
echo -e "${RED}✗ Error: Could not extract filename${NC}"
exit 1
fi
formats=("UHD" "1080x1920")
destinations=("$UHD_DIR" "$PORTRAIT_DIR")
output_files=()
for i in "${!formats[@]}"; do
format="${formats[$i]}"
dest_dir="${destinations[$i]}"
download_url="http://www.bing.com${urlbase}_${format}.jpg"
temp_jpg="$TEMP_DIR/${filename}_${format}.jpg"
output_avif="$dest_dir/${filename}.avif"
if curl -f -s -o "$temp_jpg" "$download_url"; then
/opt/homebrew/bin/magick "$temp_jpg" "$output_avif" 2>/dev/null
output_files+=("$output_avif")
else
echo -e "${RED}✗ Download failed: $download_url${NC}"
exit 1
fi
done
echo "$copyright" > "$INFO_FILE"
osascript <<EOF >/dev/null 2>&1
tell application "System Events"
set desktopCount to count of desktops
if desktopCount >= 1 then
tell desktop 1
set picture to "${output_files[1]}"
end tell
end if
if desktopCount >= 2 then
tell desktop 2
set picture to "${output_files[0]}"
end tell
end if
end tell
EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.bing-wallpaper</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>~/Pictures/Bing/bing-wallpaper.sh</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>8</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<dict>
<key>Hour</key>
<integer>9</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<dict>
<key>Hour</key>
<integer>10</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<dict>
<key>Hour</key>
<integer>11</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</array>
<key>RunAtLoad</key>
<false/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment