-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.sh
executable file
·191 lines (168 loc) · 4.89 KB
/
action.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
#!/bin/bash
q=$1
data="$HOME/Library/Application Support/Alfred 2/Workflow Data/com.spr.f.lux"
saveColors() {
night=`defaults read $HOME/Library/Preferences/org.herf.Flux.plist nightColorTemp`
day=`defaults read $HOME/Library/Preferences/org.herf.Flux.plist dayColorTemp`
late=`defaults read $HOME/Library/Preferences/org.herf.Flux.plist lateColorTemp`
# We're going to save the previous settings so that we can restore them later.
echo "night=$night" > "$data/reset"
echo "day=$day" >> "$data/reset"
echo "late=$late" >> "$data/reset"
}
setUniform() {
defaults write $HOME/Library/Preferences/org.herf.Flux.plist nightColorTemp -integer $1
defaults write $HOME/Library/Preferences/org.herf.Flux.plist dayColorTemp -integer $1
defaults write $HOME/Library/Preferences/org.herf.Flux.plist lateColorTemp -integer $1
}
restoreFlux() {
while read line
do
arr=${line//=/ }
for x in $arr
do
if [ -z $key ]; then
key=$x
else
defaults write $HOME/Library/Preferences/org.herf.Flux.plist "$key"ColorTemp -integer "$x"
key=''
fi
done
done < "$data/reset"
}
# Arguments that need to be parsed.
if [[ $q =~ "color" ]]; then
if [ -f "$data/mood" ]; then
rm "$data/mood"
fi
if [ -f "$data/darkroom" ]; then
rm "$data/darkroom"
fi
q=${q#color-}
color=${q#*-}
state=${q%-*}
if [ "$state" = "sunset" ]; then
state="night"
fi
defaults write $HOME/Library/Preferences/org.herf.Flux.plist "$state"ColorTemp -integer "$color"
echo "Color has been set to $color."
exit 0
fi
# Disable
if [[ $q =~ "disable" ]]; then
if [ -f "$data/mood" ]; then
rm "$data/mood"
fi
if [ -f "$data/darkroom" ]; then
rm "$data/darkroom"
fi
saveColors
if [ $q = 'disable' ]; then
nohup php disable.php 3600 > /dev/null 2>&1 &
echo "F.lux has been disabled for one hour."
elif [ $q = 'sunrise' ]; then
nohup php disable.php sunrise > /dev/null 2>&1 &
echo "F.lux has been disabled until sunrise."
else
nohup php disable.php ${q##disable-} > /dev/null 2>&1 &
readable=`./date.sh secondsToHumanTime ${q##disable-}`
echo "F.lux has been disabled for $readable"
fi
exit 0
fi
if [[ $q =~ "set-" ]]; then
q=${q#set-}
key=${q%-*}
value=${q#*-}
if [ $key = "wakeTime" ]; then
if [[ $value =~ : ]]; then
hour=${value%":"*}
minute=${value#*":"}
value=$(( hour*60 + minute ))
else
echo "Error: 'wakeTime' must be set in HH:MM format."
exit 0
fi
else
if [[ $value -lt 1000 ]]; then
value=1000
elif [[ $value -gt 27000 ]]; then
value=27000
fi
fi
defaults write $HOME/Library/Preferences/org.herf.Flux.plist "$key" -integer "$value"
echo "Set $key $value."
exit 0
fi
# Simple arguments... for now.
# Just open flux
if [[ $q = "open" ]]; then
if [ -e "/Applications/Flux.app" ]; then
open /Applications/Flux.app
echo "Opening F.lux"
elif [ -e "$HOME/Applications/Flux.app" ]; then
open "$HOME/Applications/Flux.app"
echo "Opening F.lux"
else
echo "Cannot find F.lux. Please open it manually."
fi
exit 0
fi
# Restore flux from mood/darkroom/disable. Might be overdoing it.
if [[ $q = "restore" ]]; then
restoreFlux
if [ -f "$data/mood" ]; then
rm "$data/mood"
restoreFlux
echo "Restoring F.lux to normal. Please be patient."
fi
if [ -f "$data/darkroom" ]; then
rm "$data/darkroom"
restoreFlux
osascript -e 'tell application "System Events"' \
-e 'tell application processes' \
-e 'key code 28 using {command down, option down, control down}' \
-e 'end tell' \
-e 'end tell'
echo "Restoring F.lux to normal. Please be patient."
fi
if [ -f "$data/disable" ]; then
rm "$data/disable"
restoreFlux
echo "Re-enabling Flux."
fi
exit 0
fi
# Send it to darkroom mode
if [[ $q = "darkroom" ]]; then
saveColors
setUniform 1000
osascript -e 'tell application "System Events"' \
-e 'tell application processes' \
-e 'key code 28 using {command down, option down, control down}' \
-e 'end tell' \
-e 'end tell'
touch "$data/darkroom"
echo Darkroom Mode has started.
exit 0
fi
# Enter Mood lighting mode
if [[ $q = "mood" ]]; then
saveColors
setUniform 2400
# Options for flicker.php... we're only allowing dark and windy for now.
# dark, dim, normal, bright
# calm, breeze, windy, hurricane
touch "$data/mood"
nohup php flicker.php 'dark' 'windy' "$data/mood" > /dev/null 2>&1 &
echo Mood lighting shall now commence.
exit 0
fi
# Reset Values
if [[ $q = "reset" ]]; then
defaults write $HOME/Library/Preferences/org.herf.Flux.plist nightColorTemp -integer 3400
defaults write $HOME/Library/Preferences/org.herf.Flux.plist dayColorTemp -integer 6500
defaults write $HOME/Library/Preferences/org.herf.Flux.plist lateColorTemp -integer 3400
echo "F.lux has been reset to defaults. (Day: 6500; Night: 3400; Late: 3400)"
exit 0
fi