forked from adi1090x/dynamic-wallpaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwall.sh
executable file
·199 lines (181 loc) · 5.08 KB
/
dwall.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env bash
## Author : Aditya Shakya (adi1090x)
## Mail : adi1090x@gmail.com
## Github : @adi1090x
## Reddit : @adi1090x
## Colors
R='\033[1;31m'
G='\033[1;32m'
Y='\033[1;33m'
B='\033[1;34m'
M='\033[1;35m'
C='\033[0;36m'
W='\033[1;37m'
# zsh fix
set -o shwordsplit 2>/dev/null
# set wallpaper in kde
setkde() {
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "
var allDesktops = desktops();
print (allDesktops);
for (i=0;i<allDesktops.length;i++) {
d = allDesktops[i];
d.wallpaperPlugin = 'org.kde.image';
d.currentConfigGroup = Array('Wallpaper',
'org.kde.image',
'General');
d.writeConfig('Image', 'file://"$1"')
}"
}
case "$OSTYPE" in
linux*)
DIR="/usr/share/dynamic-wallpaper"
;;
*)
DIR="/usr/share/dynamic-wallpaper"
;;
esac
case "$OSTYPE" in
linux*)
TIME="$(date +%k)"
;;
*)
TIME="$(date +%k)"
;;
esac
## For XFCE
if [[ "$OSTYPE" == "linux"* ]]; then
SCREEN="$(xrandr --listactivemonitors | awk -F ' ' 'END {print $1}' | tr -d \:)"
MONITOR="$(xrandr --listactivemonitors | awk -F ' ' 'END {print $2}' | tr -d \*+)"
fi
case "$OSTYPE" in
linux*)
if [ -n "$SWAYSOCK" ]; then
SETTER="eval ogurictl output '*' --image";
elif [[ "$DESKTOP_SESSION" =~ ^(MATE|Mate|mate)$ ]]; then
SETTER="gsettings set org.mate.background picture-filename";
elif [[ "$DESKTOP_SESSION" =~ ^(Xfce Session|xfce session|XFCE|xfce|Xubuntu|xubuntu)$ ]]; then
SETTER="xfconf-query --channel xfce4-desktop --property /backdrop/screen$SCREEN/monitor$MONITOR/workspace0/last-image --set";
elif [[ "$DESKTOP_SESSION" =~ ^(LXDE|Lxde|lxde)$ ]]; then
SETTER="pcmanfm --set-wallpaper";
elif [[ "$DESKTOP_SESSION" =~ ^(/usr/share/xsessions/plasma|NEON|Neon|neon|PLASMA|Plasma|plasma|KDE|Kde|kde)$ ]]; then
SETTER=setkde;
elif [[ "$DESKTOP_SESSION" =~ ^(PANTHEON|Pantheon|pantheon|GNOME|Gnome|gnome|Gnome-xorg|gnome-xorg|UBUNTU|Ubuntu|ubuntu|DEEPIN|Deepin|deepin|POP|Pop|pop)$ ]]; then
SETTER="gsettings set org.gnome.desktop.background picture-uri";
else
SETTER="feh --bg-scale";
fi
;;
*)
if [ -n "$SWAYSOCK" ]; then
SETTER="eval ogurictl output '*' --image";
elif [[ "$DESKTOP_SESSION" =~ ^(MATE|Mate|mate)$ ]]; then
SETTER="gsettings set org.mate.background picture-filename";
elif [[ "$DESKTOP_SESSION" =~ ^(Xfce Session|xfce session|XFCE|xfce|Xubuntu|xubuntu)$ ]]; then
SETTER="xfconf-query --channel xfce4-desktop --property /backdrop/screen$SCREEN/monitor$MONITOR/workspace0/last-image --set";
elif [[ "$DESKTOP_SESSION" =~ ^(LXDE|Lxde|lxde)$ ]]; then
SETTER="pcmanfm --set-wallpaper";
elif [[ "$DESKTOP_SESSION" =~ ^(/usr/share/xsessions/plasma|NEON|Neon|neon|PLASMA|Plasma|plasma|KDE|Kde|kde)$ ]]; then
SETTER=setkde;
elif [[ "$DESKTOP_SESSION" =~ ^(PANTHEON|Pantheon|pantheon|GNOME|Gnome|gnome|Gnome-xorg|gnome-xorg|UBUNTU|Ubuntu|ubuntu|DEEPIN|Deepin|deepin|POP|Pop|pop)$ ]]; then
SETTER="gsettings set org.gnome.desktop.background picture-uri";
else
SETTER="feh --bg-scale";
fi
;;
esac
STYLE=
RUN_ONCE=false
set_wallpaper() {
image="$DIR/images/$STYLE/$1"
if [ -f "$image.png" ]; then
FORMAT="png"
elif [ -f "$image.jpg" ]; then
FORMAT="jpg"
else
echo -e $R"Invalid theme/style, Try again."; exit 1;
fi
if [ $FORMAT ]; then
$SETTER "$image.$FORMAT"
mkdir -p "$HOME/.cache/dwall/"
echo "$image.$FORMAT" > "$HOME/.cache/dwall/currentimage"
return;
fi
}
main() {
num=$(($TIME/1))
set_wallpaper "$num"
}
usage() {
available_styles=($(ls $DIR/images))
echo
echo -e $R"Dynamic Wallpaper V1.0"
echo -e $G"Simple program to set a dynamic desktop background based on current time."
echo -e $Y"Developed By - Aditya Shakya (@adi1090x)"
echo
echo -e $B"usage: dwall [-s] style [-o] style [-h]"
echo
echo -e $M"-s style name of theme/style."
echo -e $M"-o style Run once and exit, useful for schedulers (cron)."
echo -e $M"-h help show this usage/help message."
echo
echo -e $C"Styles Dir: $DIR/images"
echo -e $C"Exports the path of the current image in ~/.cache/dwall/currentimage."
echo
printf $G"Available styles/themes: "
printf -- $Y'%s ' "${available_styles[@]}"
printf -- '\n\n'
}
init() {
if [ "$RUN_ONCE" == "true" ]; then
main;
reset_color;
exit 0;
fi
while true; do
main && sleep 60 && exec $DIR/dwall.sh -s $STYLE
done
}
is_valid_style() {
available_styles=($(ls $DIR/images))
for i in "${available_styles[@]}"; do
[ "$i" == "$1" ] && STYLE=$(echo "$1")
done
}
reset_color() {
tput sgr0 # reset attributes
tput op # reset color
}
is_valid_style "$1"
while getopts ":s:o:h" opt; do
case ${opt} in
s )
STYLE=$OPTARG
;;
o )
RUN_ONCE=true
STYLE=$OPTARG
;;
h )
usage
reset_color
exit 0
;;
\?)
echo -e $R"Unknown option,$G run dwall -h"
reset_color
exit 1
;;
: )
echo -e $R"Invalid:$G -$OPTARG$R requires an argument."
reset_color
exit 1
;;
esac
done
if [ "$STYLE" ]; then
init
else
usage
reset_color
fi