Class: OmniFocus

Inherits:
Object show all
Defined in:
lib/omnifocus.rb,
lib/omnifocus.rb

Overview

Synchronizes bug tracking systems to omnifocus.

Some definitions:

bts: bug tracking system SYSTEM: a tag uniquely identifying the bts bts_id: a string uniquely identifying a task: SYSTEM(-projectname)?#id

Defined Under Namespace

Classes: Context, Project, Task, Thingy

Constant Summary collapse

VERSION =
"2.4.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOmniFocus

Returns a new instance of OmniFocus.



71
72
73
74
# File 'lib/omnifocus.rb', line 71

def initialize
  @bug_db   = Hash.new { |h,k| h[k] = {} }
  @existing = {}
end

Instance Attribute Details

#bug_dbObject (readonly)

bug_db =

project => {
  bts_id => [task_name, url, due, defer], # only on BTS     = add to OF
  bts_id => {field=>value, ...,          # only on BTS     = OF and maybe BTS. Update fields
  bts_id => true,                         # both BTS and OF = don't touch
}

}



43
44
45
# File 'lib/omnifocus.rb', line 43

def bug_db
  @bug_db
end

#existingObject (readonly)

existing =

bts_id => project,



50
51
52
# File 'lib/omnifocus.rb', line 50

def existing
  @existing
end

Class Method Details

._load_pluginsObject

Load any file matching “omnifocus/*.rb”



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/omnifocus.rb', line 55

def self._load_plugins
  @__loaded__ ||=
    begin
      filter = ARGV.shift
      loaded = {}
      Gem.find_files("omnifocus/*.rb").each do |path|
        name = File.basename path
        next if loaded[name]
        next unless path.index filter if filter
        require path
        loaded[name] = true
      end
      true
    end
end

._pluginsObject

Return all the plugin modules that have been loaded.



225
226
227
228
229
230
231
232
# File 'lib/omnifocus.rb', line 225

def self._plugins
  _load_plugins

  constants.
    reject { |mod| mod =~ /^[A-Z_]+$/ }.
    map    { |mod| const_get mod }.
    reject { |mod| Class === mod }
end

.method_missing(msg, *args) ⇒ Object



268
269
270
271
# File 'lib/omnifocus.rb', line 268

def self.method_missing(msg, *args)
  of = OmniFocus.new
  of.send("cmd_#{msg}", *args)
end

Instance Method Details

#active_projectObject



821
822
823
# File 'lib/omnifocus.rb', line 821

def active_project
  its.status.eq(:active)
end

#active_projectsObject



857
858
859
860
861
# File 'lib/omnifocus.rb', line 857

def active_projects
  self.omnifocus.flattened_projects[active_project].get.map { |p|
    Project.new omnifocus, p
  }
end

#add_hours(t, n) ⇒ Object



332
333
334
# File 'lib/omnifocus.rb', line 332

def add_hours t, n
  t + (n * 3600).to_i
end

#aggregate(collection) ⇒ Object



738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'lib/omnifocus.rb', line 738

def aggregate collection
  h = Hash.new { |h1,k1| h1[k1] = Hash.new { |h2,k2| h2[k2] = [] } }
  p = Hash.new 0

  collection.each do |thing|
    name = thing.name
    ri   = case thing
           when Project then
             thing.review_interval
           when Task then
             thing.repetition
           else
             raise "unknown type: #{thing.class}"
           end
    date = case thing
           when Project then
             thing.next_review_date
           when Task then
             thing.due_date
           else
             raise "unknown type: #{thing.class}"
           end

    date = if date then
             date.strftime("%Y-%m-%d %a")
           else
             "unscheduled"
           end

    time = ri ? "#{ri[:steps]}#{ri[:unit].to_s[0,1]}" : "NR"

    p[time] += 1
    h[date][time] << name
  end

  return h, p
end

#aggregate_releasesObject



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/omnifocus.rb', line 489

def aggregate_releases
  rels = context "Releasing"

  tasks = Hash.new { |h,k| h[k] = [] } # name => tasks
  projs = Hash.new { |h,k| h[k] = [] } # step => projs

  rels.tasks.each do |task|
    proj = task.project
    tasks[proj.name] << task
    projs[proj.review_interval[:steps]] << proj
  end

  projs.each do |k, a|
    # helps stabilize and prevent random shuffling
    projs[k] = a.uniq_by { |p| p.name }.sort_by { |p|
      tasks[p.name].map(&:name).min
    }
  end

  return rels, tasks, projs
end

#all_contextsObject



841
842
843
844
845
# File 'lib/omnifocus.rb', line 841

def all_contexts
  self.omnifocus.flattened_contexts.get.map { |c|
    Context.new omnifocus, c
  }
end

#all_projectsObject



829
830
831
832
833
# File 'lib/omnifocus.rb', line 829

def all_projects
  self.omnifocus.flattened_projects.get.map { |p|
    Project.new omnifocus, p
  }
end

#all_subtasks(task) ⇒ Object



84
85
86
# File 'lib/omnifocus.rb', line 84

def all_subtasks task
  [task] + task.tasks.get.flatten.map{|t| all_subtasks(t) }
end

#all_tasksObject



88
89
90
91
92
# File 'lib/omnifocus.rb', line 88

def all_tasks
  # how to filter on active projects. note, this causes sync problems
  # omnifocus.flattened_projects[its.status.eq(:active)].tasks.get.flatten
  omnifocus.flattened_projects.tasks.get.flatten.map{|t| all_subtasks(t) }.flatten
end

#calculate_schedule(projs) ⇒ Object



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/omnifocus.rb', line 454

def calculate_schedule projs
  all = [
         distribute(projs[1].size, 1),
         distribute(projs[2].size, 2),
         distribute(projs[3].size, 3),
         distribute(projs[5].size, 5),
         distribute(projs[7].size, 7),
        ]

  # [[1, 1, 1, 1, 1],
  #  [2, 2, 2, 2, 2, nil, 2, 2, 2, 2],
  #  [3, nil, 3, 3, nil, 3, 3, nil, 3, 3, nil, 3, 3, nil, 3],
  #  ...

  all.map! { |a|
    a.concat [nil] * (35-a.size)
    a.each_slice(5).to_a
  }

  # [[[1, 1, 1, 1, 1],     [nil, nil, nil, nil, nil], ...
  #  [[2, 2, 2, 2, 2],     [nil, 2, 2, 2, 2],         ...
  #  [[3, nil, 3, 3, nil], [3, 3, nil, 3, 3],         ...
  #  ...

  weeks = all.transpose.map { |a, *r|
    a.zip(*r).map(&:compact)
  }

  # [[[1, 2, 3, 5, 7], [1, 2], [1, 2, 3], [1, 2, 3], [1, 2, 5]],
  #  [[3], [2, 3, 7], [2], [2, 3, 5], [2, 3]],
  #  ...

  weeks
end

#cmd_fix_review_dates(args) ⇒ Object

TODO: merge into reschedule



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/omnifocus.rb', line 412

def cmd_fix_review_dates args # TODO: merge into reschedule
  skip = ARGV.first == "-n"

  projs = all_projects.group_by { |proj| proj.review_interval[:steps] }

  projs.each do |k, a|
    # helps stabilize and prevent random shuffling
    projs[k] = a.sort_by { |p| [p.next_review_date, p.name] }
  end

  now = hour 0
  fri = if now.wday == 5 then
          now
        else
          now - 86400 * (now.wday-5)
        end

  no_autosave_during do
    projs.each do |unit, a|
      day = fri

      steps = (a.size.to_f / unit).ceil

      a.each_with_index do |proj, i|
        if proj.next_review_date != day then
          warn "Fixing #{unit} #{proj.name} to #{day}"
          proj.thing.next_review_date.set day unless skip
        end

        day += 86400 * 7 if (i+1) % steps == 0
      end
    end
  end
end

#cmd_help(args) ⇒ Object



391
392
393
394
395
396
397
398
399
400
# File 'lib/omnifocus.rb', line 391

def cmd_help args
  methods = OmniFocus.public_instance_methods(false).grep(/^cmd_/)
  methods.map! { |s| s[4..-1] }

  puts "Available subcommands:"

  methods.sort.each do |m|
    puts "  #{m}"
  end
end

#cmd_neww(args) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/omnifocus.rb', line 279

def cmd_neww args
  project_name = args.shift
  title = ($stdin.tty? ? args.join(" ") : $stdin.read).strip

  unless project_name && ! title.empty? then
    cmd = File.basename $0
    projects = omnifocus.flattened_projects.name.get.sort_by(&:downcase)

    warn "usage: #{cmd} new project_name title        - create a project task"
    warn "       #{cmd} new nil          title        - create an inbox task"
    warn "       #{cmd} new project      project_name - create a new project"
    warn ""
    warn "project_names = #{projects.join ", "}"
    exit 1
  end

  case project_name.downcase
  when "nil" then
    omnifocus.make :new => :inbox_task, :with_properties => {:name => title}
  when "project" then
    rep        = weekly
    start_date = hour 0
    due_date1  = hour 16
    due_date2  = hour 16.5

    cont = context("Releasing").thing
    proj = make nerd_projects, :project, title, :review_interval => rep

    props = {
      :repetition => rep,
      :context    => cont,
      :defer_date => start_date
    }

    make proj, :task, "Release #{title}", props.merge(:due_date => due_date1)
    make proj, :task, "Triage #{title}", props.merge(:due_date => due_date2)
  else
    projects = omnifocus.sections.projects[its.name.eq(project_name)]
    project = projects.get.flatten.grep(Appscript::Reference).first
    project.make :new => :task, :with_properties => {:name => title}

    puts "created task in #{project_name}: #{title}"
  end
end

#cmd_projects(args) ⇒ Object



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/omnifocus.rb', line 343

def cmd_projects args
  h = Hash.new 0
  n = 0

  self.active_projects.each do |project|
    name  = project.name
    count = project.unscheduled_tasks.size
    ri    = project.review_interval
    time  = "#{ri[:steps]}#{ri[:unit].to_s[0,1]}"

    next unless count > 0

    n += count
    h["#{name} (#{time})"] = count
  end

  puts "%5d: %3d%%: %s" % [n, 100, "Total"]
  puts
  h.sort_by { |name, count| -count }.each do |name, count|
    puts "%5d: %3d%%: %s" % [count, 100 * count / n, name]
  end
end

#cmd_reschedule(args) ⇒ Object



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/omnifocus.rb', line 597

def cmd_reschedule args
  skip = ARGV.first == "-n"

  rels, tasks, projs = aggregate_releases

  no_autosave_during do
    warn "Checking project review intervals..."
    fix_project_review_intervals rels, skip

    warn "Checking releasing task numeric prefixes (if any)"
    fix_release_task_names projs, tasks, skip

    warn "Checking releasing task schedules"
    fix_release_task_schedule projs, tasks, skip
  end
end

#cmd_review(args) ⇒ Object



627
628
629
# File 'lib/omnifocus.rb', line 627

def cmd_review args
  print_aggregate_report live_projects
end

#cmd_schedule(args) ⇒ Object



402
403
404
405
406
407
408
409
410
# File 'lib/omnifocus.rb', line 402

def cmd_schedule args
  name = args.shift or abort "need a context or project name"

  cp = context(name) || project(name)

  abort "Context/Project not found: #{name}" unless cp

  print_aggregate_report cp.tasks, :long
end

#cmd_sync(args) ⇒ Object



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
# File 'lib/omnifocus.rb', line 234

def cmd_sync args
  # do this all up front so we can REALLY fuck shit up with plugins
  self.class._plugins.each do |plugin|
    extend plugin
  end

  prepopulate_existing_tasks

  self.class._plugins.each do |plugin|
    name = plugin.name.split(/::/).last.downcase
    warn "scanning #{name}"
    send "populate_#{name}_tasks"
  end

  if $DEBUG then
    require 'pp'
    p :existing
    pp existing
    p :bug_db
    pp bug_db
  end

  create_missing_projects
  update_tasks
end

#cmd_time(args) ⇒ Object



614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/omnifocus.rb', line 614

def cmd_time args
  m = 0

  all_tasks.map { |task|
    task.estimated_minutes.get
  }.grep(Numeric).each { |t|
    m += t
  }

  puts "all tasks = #{m} minutes"
  puts "          = %.2f hours" % (m / 60.0)
end

#cmd_wtf(args) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/omnifocus.rb', line 366

def cmd_wtf args
  filter = its.completed.eq(false).and(its.repetition.eq(:missing_value))

  h1 = Hash.new 0
  omnifocus.flattened_contexts.get.each do |context|
    context.tasks[filter].get.each do |task|
      h1[[task.containing_project.name.get, context.name.get].join(": ")] += 1
    end
  end

  h2 = Hash.new 0
  omnifocus.flattened_contexts.get.each do |context|
    h2[context.name.get] += context.tasks[filter].count
  end

  h3 = Hash.new 0
  omnifocus.flattened_projects.get.each do |project|
    h3[project.name.get] += project.tasks[filter].count
  end

  top(h1).zip(top(h2), top(h3)).each do |a|
    puts "%-26s%-26s%-26s" % a
  end
end

#context(name) ⇒ Object



847
848
849
850
# File 'lib/omnifocus.rb', line 847

def context name
  context = self.omnifocus.flattened_contexts[name].get rescue nil
  Context.new omnifocus, context if context
end

#create_missing_projectsObject

Create any projects in bug_db that aren’t in omnifocus, add under the nerd folder.



160
161
162
163
164
165
166
# File 'lib/omnifocus.rb', line 160

def create_missing_projects
  (bug_db.keys - nerd_projects.projects.name.get).each do |name|
    warn "creating project #{name}"
    next if $DEBUG
    make nerd_projects, :project, name
  end
end

#distribute(count, weeks) ⇒ Object



447
448
449
450
451
452
# File 'lib/omnifocus.rb', line 447

def distribute count, weeks
  count = count.to_f
  d = 5 * weeks
  hits = (1..d).step(d/count).map(&:round)
  (1..d).map { |n| hits.include?(n) ? weeks : nil }
end

#fix_project_review_intervals(rels, skip) ⇒ Object



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/omnifocus.rb', line 511

def fix_project_review_intervals rels, skip
  rels.tasks.each do |task|
    begin
      proj = task.project

      t_ri = task.repetition[:steps]
      p_ri = proj.review_interval[:steps]

      if t_ri != p_ri then
        warn "Fixing #{task.name} to #{p_ri} weeks"

        rep = {
               :recurrence        => "FREQ=WEEKLY;INTERVAL=#{p_ri}",
               :repetition_method => :fixed_repetition,
              }

        task.thing.repetition_rule.set :to => rep unless skip
      end
    rescue => e
      warn "ERROR: skipping '#{task.name}' in '#{proj.name}': #{e.message}"
    end
  end
end

#fix_release_task_names(projs, tasks, skip) ⇒ Object



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/omnifocus.rb', line 535

def fix_release_task_names projs, tasks, skip
  projs.each do |step, projects|
    projects.each do |project|
      tasks[project.name].each do |task|
        if task.name =~ /^(\d+(\.\d+)?)/ then
          if $1.to_i != step then
            new_name = task.name.sub(/^(\d+(\.\d+)?)/, step.to_s)
            puts "renaming to #{new_name}"
            task.thing.name.set new_name unless skip
          end
        end
      end
    end
  end
end

#fix_release_task_schedule(projs, tasks, skip) ⇒ Object



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/omnifocus.rb', line 551

def fix_release_task_schedule projs, tasks, skip
  weeks = calculate_schedule projs

  now = hour 0
  mon = if now.wday == 1 then
          now
        else
          now - 86400 * (now.wday-1)
        end

  weeks.each_with_index do |week, wi|
    week.each_with_index do |day, di|
      next if day.empty?
      delta = wi*7 + di
      date = mon + 86400 * delta

      day.each do |rank|
        p = projs[rank].shift
        t = tasks[p.name]

        t.each do |task|
          if task.start_date != date then
            due_date1  = add_hours date, 16
            due_date2  = add_hours date, 16.5

            warn "Fixing #{p.name} to #{date.strftime "%Y-%m-%d"}"

            next if skip

            case task.name
            when /Release/ then
              task.start_date = date
              task.due_date = due_date1
            when /Triage/ then
              task.start_date = date
              task.due_date = due_date2
            else
              warn "Unknown task name: #{task.name}"
            end
          end
        end
      end
    end
  end
end

#hour(n) ⇒ Object



336
337
338
339
340
341
# File 'lib/omnifocus.rb', line 336

def hour n
  t = Time.now
  midnight = Time.gm t.year, t.month, t.day
  midnight -= t.utc_offset
  midnight + (n * 3600).to_i
end

#itsObject

:nodoc:



76
77
78
# File 'lib/omnifocus.rb', line 76

def its # :nodoc:
  Appscript.its
end

#live_projectsObject



835
836
837
838
839
# File 'lib/omnifocus.rb', line 835

def live_projects
  self.omnifocus.flattened_projects[non_dropped_project].get.map { |p|
    Project.new omnifocus, p
  }
end

#make(target, type, name, extra = {}) ⇒ Object

Utility shortcut to make a new thing with a name via appscript.



97
98
99
# File 'lib/omnifocus.rb', line 97

def make target, type, name, extra = {}
  target.make :new => type, :with_properties => { :name => name }.merge(extra)
end

#mechanizeObject

Returns the mechanize agent



151
152
153
154
# File 'lib/omnifocus.rb', line 151

def mechanize
  require 'mechanize'
  @mechanize ||= Mechanize.new
end

#nerd_projectsObject

Get all projects under the nerd folder



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/omnifocus.rb', line 104

def nerd_projects
  unless defined? @nerd_projects then
    @nerd_projects = omnifocus.folders[NERD_FOLDER]

    begin
      @nerd_projects.get
    rescue
      make omnifocus, :folder, NERD_FOLDER
    end
  end

  @nerd_projects
end

#no_autosave_duringObject



877
878
879
880
881
882
# File 'lib/omnifocus.rb', line 877

def no_autosave_during
  self.omnifocus.will_autosave.set false
  yield
ensure
  self.omnifocus.will_autosave.set true
end

#non_dropped_projectObject



825
826
827
# File 'lib/omnifocus.rb', line 825

def non_dropped_project
  its.status.eq(:dropped).not
end

#omnifocusObject



80
81
82
# File 'lib/omnifocus.rb', line 80

def omnifocus
  @omnifocus ||= Appscript.app('OmniFocus').default_document
end

#prepopulate_existing_tasksObject

Walk all omnifocus tasks under the nerd folder and add them to the bug_db hash if they match a bts_id.



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
# File 'lib/omnifocus.rb', line 122

def prepopulate_existing_tasks
  prefixen = self.class._plugins.map { |klass| klass::PREFIX rescue nil }
  of_tasks = nil

  prefix_re = /^(#{Regexp.union prefixen}(?:-[\w\s.-]+)?\#\d+)/

  if prefixen.all? then
    of_tasks = all_tasks.find_all { |task|
      task.name.get =~ prefix_re
    }
  else
    warn "WA"+"RN: Older plugins installed. Falling back to The Old Ways"

    of_tasks = all_tasks.find_all { |task|
      task.name.get =~ /^([A-Z]+(?:-[\w-]+)?\#\d+)/
    }
  end

  of_tasks.each do |of_task|
    ticket_id = of_task.name.get[prefix_re, 1]
    project                    = of_task.containing_project.name.get
    existing[ticket_id]        = project
    bug_db[project][ticket_id] = false
  end
end


728
729
730
731
732
733
734
735
736
# File 'lib/omnifocus.rb', line 728

def print_aggregate_report collection, long = false
  h, p = self.aggregate collection

  self.print_occurrence_table h, p

  puts

  self.print_details h, long
end


805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# File 'lib/omnifocus.rb', line 805

def print_details h, long = false
  h.sort.each do |date, plan|
    puts date
    plan.sort.each do |period, things|
      next if things.empty?
      if long then
        things.sort.each do |thing|
          puts "  #{period}: #{thing}"
        end
      else
        puts "  #{period}: #{things.sort.join ', '}"
      end
    end
  end
end


776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/omnifocus.rb', line 776

def print_occurrence_table h, p
  p = p.sort_by { |priority, _|
    case priority
    when /(\d+)(.)/ then
      n, u = $1.to_i, $2
      n *= {"d" => 1, "w" => 7, "m" => 28, "y" => 365}[u]
    when "NR" then
      1/0.0
    else
      warn "unparsed: #{priority.inspect}"
      0
    end
  }

  units = p.map(&:first)

  total = 0
  hdr = "%14s%s %3s " + "%2s " * units.size
  fmt = "%14s: %3d " + "%2s " * units.size
  puts hdr % ["date", "\\", "tot", *units]
  h.sort.each do |date, plan|
    counts = units.map { |n| plan[n].size  }
    subtot = counts.inject(&:+)
    total += subtot
    puts fmt % [date, subtot, *counts]
  end
  puts hdr % ["total", ":", total, *p.map(&:last)]
end

#project(name) ⇒ Object



852
853
854
855
# File 'lib/omnifocus.rb', line 852

def project name
  project = self.omnifocus.flattened_projects[name].get
  Project.new omnifocus, project if project
end

#regular_tasksObject



863
864
865
# File 'lib/omnifocus.rb', line 863

def regular_tasks
  (its.value.class_.eq(:item).not).and(its.value.class_.eq(:folder).not)
end

#selected_tasksObject



871
872
873
874
875
# File 'lib/omnifocus.rb', line 871

def selected_tasks
  window.content.selected_trees[regular_tasks].value.get.map { |t|
    Task.new self, t
  }
end

#top(hash, n = 10) ⇒ Object



273
274
275
276
277
# File 'lib/omnifocus.rb', line 273

def top hash, n=10
  hash.sort_by { |k,v| [-v, k] }.first(n).map { |k,v|
    "%4d %s" % [v,k[0,21]]
  }
end

#update_tasksObject

Synchronize the contents of bug_db with omnifocus, creating missing tasks and marking tasks completed as needed. See the doco for bug_db for more info on how you should populate it.



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
# File 'lib/omnifocus.rb', line 173

def update_tasks
  bug_db.each do |name, tickets|
    project = nerd_projects.projects[name]

    tickets.each do |bts_id, value|
      case value
      when true
        project.tasks[its.name.contains(bts_id)].get.each do |task|
          if task.completed.get
            puts "Re-opening #{name} # #{bts_id}"
            next if $DEBUG

            begin
              task.completed.set false
            rescue
              task.mark_incomplete
            end
          end
        end
      when false
        project.tasks[its.name.contains(bts_id)].get.each do |task|
          next if task.completed.get
          puts "Removing #{name} # #{bts_id}"
          next if $DEBUG

          begin
            task.completed.set true
          rescue
            task.mark_complete
          end
        end
      when Array
        puts "Adding #{name} # #{bts_id}"
        next if $DEBUG
        title, url = *value
        make project, :task, title, :note => url
      when Hash
        puts "Adding Detail #{name} # #{bts_id}"
        next if $DEBUG
        properties = value.clone
        title = properties.delete(:title)
        make project, :task, title, properties
      else
        abort "ERROR: Unknown value in bug_db #{bts_id}: #{value.inspect}"
      end
    end
  end
end

#weekly(n = 1) ⇒ Object



324
325
326
327
328
329
330
# File 'lib/omnifocus.rb', line 324

def weekly n=1
  {
    :unit => :week,
    :steps => n,
    :fixed_ => true,
  }
end

#windowObject



867
868
869
# File 'lib/omnifocus.rb', line 867

def window
  self.omnifocus.document_windows[1]
end