diff --git a/README.md b/README.md
index ae7111a..bd8cbc7 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ it to a directory.
The script was tested on:
-- Mac OS X 10.8 - 10.12
+- Mac OS X 10.8 - 10.12, 10.15
- Ubuntu 12.04 - 16.04
- Arch 2022.01.01
@@ -43,6 +43,9 @@ Options:
-h --help Show this screen.
--version Show version.
```
+Dependencies
+------------
+The script uses [jq](https://stedolan.github.io/jq/) to parse json output from Bing.com. Installation instructions can be found on [jq's download page](https://stedolan.github.io/jq/download/).
Configuration on Mac
--------------------
diff --git a/Tools/com.ideasftw.bing-wallpaper.plist b/Tools/com.ideasftw.bing-wallpaper.plist
index 02a5b12..b92141a 100644
--- a/Tools/com.ideasftw.bing-wallpaper.plist
+++ b/Tools/com.ideasftw.bing-wallpaper.plist
@@ -8,7 +8,14 @@
/bin/bash
/Users/username/Pictures/bing-wallpaper.sh
+ -s
+ -w
+ EnvironmentVariables
+
+ PATH
+ /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
+
LowPriorityIO
Nice
@@ -20,5 +27,9 @@
Minute
0
+ StandardErrorPath
+ /tmp/bing-wallpaper.err
+ StandardOutPath
+ /tmp/bing-wallpaper.out
diff --git a/bing-wallpaper.sh b/bing-wallpaper.sh
index 8e50708..030ba7b 100755
--- a/bing-wallpaper.sh
+++ b/bing-wallpaper.sh
@@ -42,11 +42,11 @@ print_message() {
}
# Defaults
-PICTURE_DIR="$HOME/Pictures/bing-wallpapers/"
-RESOLUTION="1920x1080"
+PICTURE_DIR="$HOME/Pictures/bing-wallpapers"
+RESOLUTION="UHD"
+BOOST=1
# Option parsing
-BOOST=1
while [[ $# -gt 0 ]]; do
key="$1"
@@ -96,6 +96,13 @@ while [[ $# -gt 0 ]]; do
shift
done
+# Test for existence of the command jq
+if ! command -v jq &> /dev/null
+then
+ echo "The command jq could not be found. Refer to the readme for how to install jq."
+ exit
+fi
+
# Set options
[ -n "$QUIET" ] && CURL_QUIET='-s'
[ -n "$SSL" ] && PROTO='https' || PROTO='http'
@@ -103,31 +110,29 @@ done
# Create picture directory if it doesn't already exist
mkdir -p "${PICTURE_DIR}"
+# Parse bing.com and acquire picture URL(s)
read -ra urls < <(curl -sL "$PROTO://www.bing.com/HPImageArchive.aspx?format=js&n=$BOOST" | \
- # Extract the image urls from the JSON response
- grep -Po '(?<=url":").*?(?=")' | \
- # Set the image resolution
+ jq -r '.images | reverse | .[] | .url' | \
sed -e "s/[[:digit:]]\{1,\}x[[:digit:]]\{1,\}/$RESOLUTION/" | \
- # FQDN the image urls
- sed -e "s/\(.*\)/${PROTO}\:\/\/www.bing.com\1/" | \
- tr "\n" " ")
+ sed -e "s/\(.*\)/$PROTO:\/\/bing.com\1/")
-for pic in "${urls[@]}"; do
+for p in "${urls[@]}"; do
if [ -z "$FILENAME" ]; then
- filename=$(echo "$pic" | sed -e 's/.*[?&;]id=\([^&]*\).*/\1/' | grep -oe '[^\.]*\.[^\.]*$')
+ filename=$(echo "$p" | sed -e 's/.*[?&;]id=\([^&]*\).*/\1/' | grep -oe '[^\.]*\.[^\.]*$')
else
filename="$FILENAME"
fi
if [ -n "$FORCE" ] || [ ! -f "$PICTURE_DIR/$filename" ]; then
- print_message "Downloading: $filename..."
- curl $CURL_QUIET -Lo "$PICTURE_DIR/$filename" "$pic"
+ print_message "Downloading: $filename from $p..."
+ curl $CURL_QUIET -Lo "$PICTURE_DIR/$filename" "$p"
else
print_message "Skipping: $filename..."
fi
done
if [ -n "$SET_WALLPAPER" ]; then
+ print_message "Setting wallpaper to $PICTURE_DIR/$filename"
/usr/bin/osascript<