-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathask_myself
executable file
·71 lines (62 loc) · 1.51 KB
/
ask_myself
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
#!/bin/bash
opts=(time_boxed
prioritized_tasks
limited_out_of_band_work
had_fun
) # the questions - whitespace is probably fine but meh
response=() # selections from applescript
score=() # csv scores
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
score_tally() {
if containsElement "$1" "${response[@]}"
then
score=( "${score[@]}" "1," )
else
score=( "${score[@]}" "0," )
fi
}
#applescript produces a list, I need an array
ascript_to_array() {
IFS=', ' read -r -a response <<< "$ascript"
}
# order of the CSV elements = order of the opts
# this script is dumb and I made the csv headers manually
# if opts change, headers must be manually fixed
build_csv () {
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
for i in "${opts[@]}"
do
:
score_tally "$i" "${response[@]}"
done
score=( "$(date +%a), $(date +%m)-$(date +%d), $(date +%Y)," "${score[@]}" )
echo "${score[@]}" >> "$DIR"/log.csv
}
ascript=$(/usr/bin/osascript << END
tell application "System Events"
Activate
set ASlist to the words of "${opts[@]}"
choose from list ASlist with prompt "what good did you do today?" with multiple selections allowed and empty selection allowed
if true
return the result as list
"export LIST=" & quoted form of list
else
error number -128
end if
end tell
END
)
main () {
if [ "$ascript" = false ]; then
exit 128
else
ascript_to_array
build_csv
fi
}
main