-
-
Notifications
You must be signed in to change notification settings - Fork 116
/
dwall.sh
executable file
·267 lines (233 loc) · 7.24 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env bash
## Author : Aditya Shakya (adi1090x)
## Mail : [email protected]
## Github : @adi1090x
## Twitter : @adi1090x
## Dynamic Wallpaper : Set wallpapers according to current time.
## Created to work better with job schedulers (cron)
## ANSI Colors (FG & BG)
RED="$(printf '\033[31m')" GREEN="$(printf '\033[32m')"
ORANGE="$(printf '\033[33m')" BLUE="$(printf '\033[34m')"
MAGENTA="$(printf '\033[35m')" CYAN="$(printf '\033[36m')"
WHITE="$(printf '\033[37m')" BLACK="$(printf '\033[30m')"
REDBG="$(printf '\033[41m')" GREENBG="$(printf '\033[42m')"
ORANGEBG="$(printf '\033[43m')" BLUEBG="$(printf '\033[44m')"
MAGENTABG="$(printf '\033[45m')" CYANBG="$(printf '\033[46m')"
WHITEBG="$(printf '\033[47m')" BLACKBG="$(printf '\033[40m')"
## Wallpaper directory
DIR="/usr/share/dynamic-wallpaper/images"
HOUR=`date +%k`
## Wordsplit in ZSH
set -o shwordsplit 2>/dev/null
## Reset terminal colors
reset_color() {
tput sgr0 # reset attributes
tput op # reset color
return
}
## Script Termination
exit_on_signal_SIGINT() {
{ printf "${RED}\n\n%s\n\n" "[!] Program Interrupted." 2>&1; reset_color; }
exit 0
}
exit_on_signal_SIGTERM() {
{ printf "${RED}\n\n%s\n\n" "[!] Program Terminated." 2>&1; reset_color; }
exit 0
}
trap exit_on_signal_SIGINT SIGINT
trap exit_on_signal_SIGTERM SIGTERM
## Prerequisite
Prerequisite() {
dependencies=(feh xrandr crontab)
for dependency in "${dependencies[@]}"; do
type -p "$dependency" &>/dev/null || {
echo -e ${RED}"[!] ERROR: Could not find ${GREEN}'${dependency}'${RED}, is it installed?" >&2
{ reset_color; exit 1; }
}
done
}
## Usage
usage() {
clear
cat <<- EOF
${RED}╺┳┓╻ ╻┏┓╻┏━┓┏┳┓╻┏━╸ ${GREEN}╻ ╻┏━┓╻ ╻ ┏━┓┏━┓┏━┓┏━╸┏━┓
${RED} ┃┃┗┳┛┃┗┫┣━┫┃┃┃┃┃ ${GREEN}┃╻┃┣━┫┃ ┃ ┣━┛┣━┫┣━┛┣╸ ┣┳┛
${RED}╺┻┛ ╹ ╹ ╹╹ ╹╹ ╹╹┗━╸ ${GREEN}┗┻┛╹ ╹┗━╸┗━╸╹ ╹ ╹╹ ┗━╸╹┗╸${WHITE}
Dwall V3.0 : Set wallpapers according to current time.
Developed By : Aditya Shakya (@adi1090x)
Usage : `basename $0` [-h] [-p] [-s style]
Options:
-h Show this help message
-p Use pywal to set wallpaper
-s Name of the style to apply
EOF
styles=(`ls "$DIR"`)
printf ${GREEN}"Available styles: "
printf -- ${ORANGE}'%s ' "${styles[@]}"
printf -- '\n\n'${WHITE}
cat <<- EOF
Examples:
`basename $0` -s beach Set wallpaper from 'beach' style
`basename $0` -p -s sahara Set wallpaper from 'sahara' style using pywal
EOF
}
## Set wallpaper in kde
set_kde() {
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"')
}"
}
## Set wallpaper in cinnamon
set_cinnamon() {
gsettings set org.cinnamon.desktop.background picture-uri "file:///$1"
}
## Set wallpaper in GNOME
set_gnome() {
gsettings set org.gnome.desktop.background picture-uri "file:///$1"
gsettings set org.gnome.desktop.screensaver picture-uri "file:///$1"
}
## Choose wallpaper setter
case "$OSTYPE" in
linux*)
if [[ "$XDG_SESSION_TYPE" == 'x11' ]]; then
if [[ "$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
SCREEN="$(xrandr --listactivemonitors | awk -F ' ' 'END {print $1}' | tr -d \:)"
MONITOR="$(xrandr --listactivemonitors | awk -F ' ' 'END {print $2}' | tr -d \*+)"
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" =~ ^(cinnamon|Cinnamon)$ ]]; then
SETTER=set_cinnamon
elif [[ "$DESKTOP_SESSION" =~ ^(/usr/share/xsessions/plasma|NEON|Neon|neon|PLASMA|Plasma|plasma|KDE|Kde|kde)$ ]]; then
SETTER=set_kde
elif [[ "$DESKTOP_SESSION" =~ ^(PANTHEON|Pantheon|pantheon|GNOME|Gnome|gnome|Gnome-xorg|gnome-xorg|UBUNTU|Ubuntu|ubuntu|DEEPIN|Deepin|deepin|POP|Pop|pop|ZORIN|Zorin|zorin|budgie-desktop)$ ]]; then
SETTER=set_gnome
else
SETTER="feh --bg-fill"
fi
elif [[ "$XDG_SESSION_TYPE" == 'wayland' ]]; then
SETTER="eval ogurictl output '*' --image"
fi
;;
esac
## Display Info
display_info() {
if [[ "$XDG_SESSION_TYPE" == 'x11' ]]; then
echo -e ${ORANGE}"[*] Setting wallpaper in ${GREEN}$XDG_SESSION_TYPE ($DESKTOP_SESSION)${ORANGE} session, using : ${MAGENTA}$SETTER"
elif [[ "$XDG_SESSION_TYPE" == 'wayland' ]]; then
if [[ ! `pidof oguri` ]]; then
echo -e ${RED}"[*] 'oguri' daemon is not running. You must start the daemon first.\n[!] Kill 'swaybg' in sway session if the wallpaper is not getting applied."
exit 1
else
echo -e ${ORANGE}"[*] Setting wallpaper in ${GREEN}$XDG_SESSION_TYPE ($XDG_SESSION_DESKTOP)${ORANGE} session, using : ${MAGENTA}$SETTER"
fi
fi
}
## Get Image
get_img() {
image="$DIR/$STYLE/$1"
# get image format
if [[ -f "${image}.png" ]]; then
FORMAT="png"
elif [[ -f "${image}.jpg" ]]; then
FORMAT="jpg"
else
echo -e ${RED}"[!] Invalid image file, Exiting..."
{ reset_color; exit 1; }
fi
}
## Set wallpaper with pywal
pywal_set() {
get_img "$1"
if [[ -x `command -v wal` ]]; then
wal -i "$image.$FORMAT"
else
echo -e ${RED}"[!] pywal is not installed on your system, exiting..."
{ reset_color; exit 1; }
fi
}
## Wallpaper Setter
set_wallpaper() {
cfile="$HOME/.cache/dwall_current"
get_img "$1"
# set wallpaper with setter
if [[ -n "$FORMAT" ]]; then
$SETTER "$image.$FORMAT"
fi
# make/update dwall cache file
if [[ ! -f "$cfile" ]]; then
touch "$cfile"
echo "$image.$FORMAT" > "$cfile"
else
echo "$image.$FORMAT" > "$cfile"
fi
}
## Check valid style
check_style() {
styles=(`ls "$DIR"`)
display_info
for i in "${styles[@]}"; do
if [[ "$i" == "$1" ]]; then
echo -e ${BLUE}"[*] Using style : ${MAGENTA}$1"
VALID='YES'
{ reset_color; break; }
else
continue
fi
done
if [[ -z "$VALID" ]]; then
echo -e ${RED}"[!] Invalid style name : ${GREEN}$1${RED}, exiting..."
{ reset_color; exit 1; }
fi
}
## Main
main() {
# get current hour
num=$(($HOUR/1))
# set wallpaper accordingly
if [[ -n "$PYWAL" ]]; then
{ pywal_set "$num"; reset_color; exit 0; }
else
{ set_wallpaper "$num"; reset_color; exit 0; }
fi
}
## Get Options
while getopts ":s:hp" opt; do
case ${opt} in
p)
PYWAL=true
;;
s)
STYLE=$OPTARG
;;
h)
{ usage; reset_color; exit 0; }
;;
\?)
echo -e ${RED}"[!] Unknown option, run ${GREEN}`basename $0` -h"
{ reset_color; exit 1; }
;;
:)
echo -e ${RED}"[!] Invalid:$GREEN -${OPTARG}$RED requires an argument."
{ reset_color; exit 1; }
;;
esac
done
## Run
Prerequisite
if [[ "$STYLE" ]]; then
check_style "$STYLE"
main
else
{ usage; reset_color; exit 1; }
fi