-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_wallpaper_winlight.sh
executable file
·48 lines (37 loc) · 1.21 KB
/
change_wallpaper_winlight.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -e
## Variables
IMAGE_DIR="/home/nico/Images/WinLight/"
WANTED_RESOL="1920x1080" #or 1080x1920
WANTED_EXT="jpg"
VALID_RESOLUTION=0
LOOP_COUNTER=0
# This is for MATE
GSETTING_PATH="org.mate.background"
GSETTING_VAR="picture-filename"
# This is for Gnome
#GSETTING_PATH="org.gnome.desktop.background"
#GSETTING_VAR="picture-uri"
## Code
# Create a listing of every image in ${IMAGE_DIR}
TMP_LIST=$(mktemp)
find "${IMAGE_DIR}" -type f -iname "*.${WANTED_EXT}" > ${TMP_LIST}
while [ $VALID_RESOLUTION -eq 0 ]; do
# Increment the loop counter
LOOP_COUNTER=$(( LOOP_COUNTER + 1 ))
# Shuffle the listing and get one file name
CANDIDATE_FILE=$(shuf -n 1 < ${TMP_LIST})
# What is the resolution of the file?
CANDIDATE_RESOL=$(convert "${CANDIDATE_FILE}" -print "Size: %wx%h\n" /dev/null |cut -f2 -d:)
# Is it the right resolution?
if [ ${WANTED_RESOL} == ${CANDIDATE_RESOL} ]; then
# Exit the loop
VALID_RESOLUTION=1;
fi
done
# Change the wallpaper
gsettings set ${GSETTING_PATH} ${GSETTING_VAR} "${CANDIDATE_FILE}"
# Log the change
logger -p info -t ${0} "After ${LOOP_COUNTER} loop, we changed the wallpaper to ${CANDIDATE_FILE}"
# Remove the temp file
rm ${TMP_LIST}