-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-multiple-wallpapers.sh
More file actions
executable file
·95 lines (60 loc) · 3.46 KB
/
set-multiple-wallpapers.sh
File metadata and controls
executable file
·95 lines (60 loc) · 3.46 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# ====================================================================== #
# Created on Linux Mint 22.3 "zena" - Cinnamon Edition #
# ====================================================================== #
# #
# > required installs (sudo apt install ...) #
# #
# xrandr #
# #
# xwallpaper #
# #
# #
# > use xrandr --query to get connected displays and their identifiers #
# #
# example output: #
# #
# DP-3 connected primary 1920x1080+1920+0 ... #
# #
# HDMI-0 connected 1920x1080+0+0 ... #
# #
# > only edit sections below with asterisks (*) in comment #
# #
# ====================================================================== #
# ******** define background image / wallpaper path(s) ********
WALLPAPERS=(
"/<path>/<to>/<image>/<file1.jpg>"
"/<path>/<to>/<image>/<file2.png>"
)
# ******** do not edit beyond this point **********************
# checks dependencies; do not edit unless you know what you're doing
command -v xrandr >/dev/null 2>&1 || { echo "xrandr not installed: use 'sudo apt install x11-xserver-utils' then try again."; exit 1; }
command -v xwallpaper >/dev/null 2>&1 || { echo "xwallpaper not installed: use 'sudo apt install xvallpaper' then try again"; exit 1; }
# display environ safety fallback - set DISPLAY only if not already defined; probably not needed in most cases but can be for systemd, cron, or early boot exec
export DISPLAY="${DISPLAY:-:0}"
# If XAUTHORITY is not set but .Xauthority exists, define it
if [[ -z "$XAUTHORITY" && -f "$HOME/.Xauthority" ]]; then
export XAUTHORITY="$HOME/.Xauthority"
fi
TIMER=0
TIMEOUT=30
# Initial check for connected displays
mapfile -t DISPLAYS < <(xrandr --query | grep " connected" | awk '{print $1}')
# if primary display not yet recognized, wait 1 second and loop
while [ ${#DISPLAYS[@]} -eq 0 ]; do
((TIMER+=1))
# if timeout reached, exit.
if ((TIMER >= TIMEOUT )); then
echo "Script timed out - monitor not detected."
exit 1
fi
# Refresh the list of connected displays
mapfile -t DISPLAYS < <(xrandr --query | grep " connected" | awk '{print $1}')
sleep 1
done
# loop length safety; will only loop as many times as it the smallest length array; basically a min() function
LOOP_LIMIT=$(( ${#DISPLAYS[@]} < ${#WALLPAPERS[@]} ? ${#DISPLAYS[@]} : ${#WALLPAPERS[@]} ))
# assign each id to a variable below (create more if necessary)
for ((i=0; i<LOOP_LIMIT; i++)); do
xwallpaper --output "${DISPLAYS[$i]}" --zoom "${WALLPAPERS[$i]}"
done