-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.sh
25 lines (18 loc) · 1.12 KB
/
app.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
Xaxis=$(/usr/sbin/system_profiler SPDisplaysDataType | awk '/Resolution/{print $2}')
Yaxis=$(/usr/sbin/system_profiler SPDisplaysDataType | awk '/Resolution/{print $4}')
splitXaxis=(${Xaxis// / })
splitYaxis=(${Yaxis// / })
tags=$(/opt/homebrew/bin/jq -r '.tags' $PWD/osx-live-wallpaper/data.json)
IFS=', ' read -r -a array <<< "$tags"
size=${#array[@]}
index=$(($RANDOM % $size))
file=$(/opt/homebrew/bin/jq -r '.file' $PWD/osx-live-wallpaper/data.json)
if [ $file == "wallpaper1" ]; then echo "$( /opt/homebrew/bin/jq '.file = "wallpaper2"' $PWD/osx-live-wallpaper/data.json )" > $PWD/osx-live-wallpaper/data.json
else echo "$( /opt/homebrew/bin/jq '.file = "wallpaper1"' $PWD/osx-live-wallpaper/data.json )" > $PWD/osx-live-wallpaper/data.json
fi
echo -e "GET https://source.unsplash.com HTTP/1.0\n\n" | nc source.unsplash.com 80 > /dev/null 2>&1
if [ $? -eq 0 ]; then
curl -L https://source.unsplash.com/${splitXaxis}x${splitYaxis}?${array[$index]} --output $PWD/osx-live-wallpaper/$file
osascript -e 'tell application "System Events" to tell every desktop to set picture to "'$PWD/osx-live-wallpaper/$file'"'
fi