forked from eliranmal/anarchist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wallpaper.sh
125 lines (94 loc) · 1.93 KB
/
wallpaper.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
#!/usr/bin/env bash
function main {
echo
validate_os
case "$1" in
help|-h)
usage
;;
set)
shift
validate_args 1 "$@"
set_wallpaper "$@"
;;
guard)
shift
validate_args 1 "$@"
guard_wallpaper "$@"
;;
*)
usage
;;
esac
}
function usage {
log "usage:
wallpaper.sh <set|guard|help> [arguments] [-h]
help
====
shows this usage guide.
set
===
sets a background image across all spaces.
arguments
---------
image-file
the path of the background image to be set.
guard
=====
watches the background image database for changes, and reverts to your image when a forbidden image is set.
arguments
---------
image-file
the path of the background image to be set.
"
}
function set_wallpaper {
local image="$1"
local db_path=/Library/Desktop\ Pictures/LPDesktop.jpg
log "setting background image to $image..."
cp -f "$image" "$db_path"
killall Dock
}
function guard_wallpaper {
local image="$1"
local db_path=/Library/Desktop\ Pictures/LPDesktop.jpg
set_wallpaper "$image"
ensure_fswatch
log "watching background image database in $db_path..."
fswatch -o "$db_path" | while read num ;
do
log "identified wallpaper change"
guard_wallpaper "$image"
break
done
}
function ensure_fswatch {
if ! hash fswatch 2>/dev/null; then
log "fswatch is not installed. installing via brew..."
brew install fswatch
fi
}
function validate_args {
local min=$1; shift
if (($# < $min)); then
usage
exit 1
fi
}
function validate_os {
if [[ $OSTYPE = "darwin"* ]]; then # mac
return 0
elif [[ $OSTYPE = "linux-gnu" ]]; then # linux
log "linux is not supported, sorry..."
exit 1
elif [[ $OSTYPE = "msys" ]]; then # windows (mingw/git-bash)
log "windows is not supported, sorry..."
exit 1
fi
}
function log {
local msg="$1"
printf "> %s\n\n" "$msg"
}
main "$@"