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
|
#!/usr/bin/env ruby -ws
$y ||= false
require "date"
class Date
def next_monday
(self..(self+7)).find { |day| day.wday == 1 }
end
end
def t n_or_a
case n_or_a
when Array
"%02d:%02d" % n_or_a
else
"%02d:%02d" % [n_or_a, 0]
end
end
def new_event title, t0, t1, where, repeat:nil
puts "set theEvent to create event event store theStore destination calendar theCal event summary %p starting date (date %p) ending date (date %p) %s" % [title, t0, t1, where]
case repeat
when :weekly, :weekdays then
puts "modify recurrence event theEvent event frequency do weekly event interval 1 repeats until endOfYear"
when :yearly then
else
end
puts "store event event theEvent event store theStore"
if repeat == :weekdays then
puts "my setToWeekdays(event_external_ID of (event info for event theEvent))"
end
end
def all_day date, title
date = Date.parse(date) if String === date
puts "-- %s all day %s" % [date, title]
d = date.to_time.strftime "%D"
new_event title, d, d, "with runs all day"
end
def event date, start, stop, repeat, title, where = nil
date = Date.parse(date) if String === date
date = date.next_year if repeat == :next_year
puts "-- %s %s-%s %-8s %s" % [date, t(start), t(stop), repeat, title]
h0, m0 = start
h1, m1 = stop
m0 ||= 0
m1 ||= 0
where = "event location %p" % LOCATION[where] if where
fmt = "%m/%d/%Y %H:%M %p"
t0 = (date.to_time + (h0 * 3600) + (m0 * 60)).strftime fmt
t1 = (date.to_time + (h1 * 3600) + (m1 * 60)).strftime fmt
new_event title, t0, t1, where, repeat:repeat
end
sun, mon, tue, wed, thu, fri, sat = (0..6).to_a
sun = sun
sat = sat
year = Date.today.year
d = Date.new(year, 1, 1)
week = (d..(d+6)).to_a
first = week.rotate(-d.wday)
first_wkdy = week.find { |day| day.wday.between? mon, fri }
if $y then
warn "setting $stdout to osascript"
$stdout = IO.popen "osascript", "w"
end
puts DATA.read
puts
LOCATION = {
:home => "Home\n[address...]",
:gym => "RCF\n[address...]",
}
may_taxes = Date.new(year, 4, 15).next_monday
oct_taxes = Date.new(year, 10, 15).next_monday
event first_wkdy, [10,30], 11, :weekdays, "Coffee & Triage"
event first[mon], 18, 23, :weekly, "Me Night", :home
event first[mon], [15,30], 16, :weekly, "1:1"
event first[mon], [16,30], [17,30], :weekly, "Pain", :gym
event first[tue], 18, 19, :weekly, "Study Group"
event first[tue], 19, 21, :weekly, "Nerd Party"
event may_taxes, 12, [12,30], :yearly, "Schedule Property Tax Payment"
event oct_taxes, 12, [12,30], :yearly, "Schedule Property Tax Payment"
event "4/23", 12, [12,30], :yearly, "No, Really! Pay Property Taxes"
event "10/23", 12, [12,30], :yearly, "No, Really! Pay Property Taxes"
event "1/1", 12, [12,30], :next_year,"Run setup_calendar_fast.rb"
all_day "4/30", "Property Taxes"
all_day "10/31", "Property Taxes"
all_day "10/15", "My Ruby Birthday (2000)"
all_day "2/28", "Seattle.rb Anniversary (2002)"
if $y then
$stdout.flush
$stdout.close
end
|