Class: OmniFocus
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.1.6"
Instance Attribute Summary collapse
-
#bug_db ⇒ Object
readonly
bug_db = { project => { bts_id => [task_name, url], # only on BTS = add to OF bts_id => true, # both BTS and OF = don’t touch bts_id => false, # only on OF = remove from OF } }.
-
#existing ⇒ Object
readonly
existing = { bts_id => project, }.
Class Method Summary collapse
-
._load_plugins ⇒ Object
Load any file matching “omnifocus/*.rb”.
-
._plugins ⇒ Object
Return all the plugin modules that have been loaded.
- .method_missing(msg, *args) ⇒ Object
Instance Method Summary collapse
- #active_project ⇒ Object
- #active_projects ⇒ Object
- #add_hours(t, n) ⇒ Object
- #aggregate(collection) ⇒ Object
- #aggregate_releases ⇒ Object
- #all_contexts ⇒ Object
- #all_projects ⇒ Object
- #all_subtasks(task) ⇒ Object
- #all_tasks ⇒ Object
- #calculate_schedule(projs) ⇒ Object
-
#cmd_fix_review_dates(args) ⇒ Object
TODO: merge into reschedule.
- #cmd_help(args) ⇒ Object
- #cmd_neww(args) ⇒ Object
- #cmd_projects(args) ⇒ Object
- #cmd_reschedule(args) ⇒ Object
- #cmd_review(args) ⇒ Object
- #cmd_schedule(args) ⇒ Object
- #cmd_sync(args) ⇒ Object
- #cmd_time(args) ⇒ Object
- #cmd_wtf(args) ⇒ Object
- #context(name) ⇒ Object
-
#create_missing_projects ⇒ Object
Create any projects in bug_db that aren’t in omnifocus, add under the nerd folder.
- #distribute(count, weeks) ⇒ Object
- #fix_project_review_intervals(rels, skip) ⇒ Object
- #fix_release_task_names(projs, tasks, skip) ⇒ Object
- #fix_release_task_schedule(projs, tasks, skip) ⇒ Object
- #hour(n) ⇒ Object
-
#initialize ⇒ OmniFocus
constructor
A new instance of OmniFocus.
-
#its ⇒ Object
:nodoc:.
- #live_projects ⇒ Object
-
#make(target, type, name, extra = {}) ⇒ Object
Utility shortcut to make a new thing with a name via appscript.
-
#mechanize ⇒ Object
Returns the mechanize agent.
-
#nerd_projects ⇒ Object
Get all projects under the nerd folder.
- #no_autosave_during ⇒ Object
- #non_dropped_project ⇒ Object
- #omnifocus ⇒ Object
-
#prepopulate_existing_tasks ⇒ Object
Walk all omnifocus tasks under the nerd folder and add them to the bug_db hash if they match a bts_id.
- #print_aggregate_report(collection, long = false) ⇒ Object
- #print_details(h, long = false) ⇒ Object
- #print_occurrence_table(h, p) ⇒ Object
- #project(name) ⇒ Object
- #regular_tasks ⇒ Object
- #selected_tasks ⇒ Object
- #top(hash, n = 10) ⇒ Object
-
#update_tasks ⇒ Object
Synchronize the contents of bug_db with omnifocus, creating missing tasks and marking tasks completed as needed.
- #weekly(n = 1) ⇒ Object
- #window ⇒ Object
Constructor Details
#initialize ⇒ OmniFocus
Returns a new instance of OmniFocus.
68 69 70 71 |
# File 'lib/omnifocus.rb', line 68 def initialize @bug_db = Hash.new { |h,k| h[k] = {} } @existing = {} end |
Instance Attribute Details
#bug_db ⇒ Object (readonly)
bug_db = {
project => {
bts_id => [task_name, url], # only on BTS = add to OF
bts_id => true, # both BTS and OF = don't touch
bts_id => false, # only on OF = remove from OF
}
}
40 41 42 |
# File 'lib/omnifocus.rb', line 40 def bug_db @bug_db end |
#existing ⇒ Object (readonly)
existing =
bts_id => project,
47 48 49 |
# File 'lib/omnifocus.rb', line 47 def existing @existing end |
Class Method Details
._load_plugins ⇒ Object
Load any file matching “omnifocus/*.rb”
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omnifocus.rb', line 52 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 |
._plugins ⇒ Object
Return all the plugin modules that have been loaded.
206 207 208 209 210 211 212 213 |
# File 'lib/omnifocus.rb', line 206 def self._plugins _load_plugins constants. reject { |mod| mod =~ /^[A-Z_]+$/ }. map { |mod| const_get mod }. reject { |mod| Class === mod } end |
Instance Method Details
#active_project ⇒ Object
798 799 800 |
# File 'lib/omnifocus.rb', line 798 def active_project its.status.eq(:active) end |
#active_projects ⇒ Object
834 835 836 837 838 |
# File 'lib/omnifocus.rb', line 834 def active_projects self.omnifocus.flattened_projects[active_project].get.map { |p| Project.new omnifocus, p } end |
#add_hours(t, n) ⇒ Object
313 314 315 |
# File 'lib/omnifocus.rb', line 313 def add_hours t, n t + (n * 3600).to_i end |
#aggregate(collection) ⇒ Object
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
# File 'lib/omnifocus.rb', line 715 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_releases ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/omnifocus.rb', line 470 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_contexts ⇒ Object
818 819 820 821 822 |
# File 'lib/omnifocus.rb', line 818 def all_contexts self.omnifocus.flattened_contexts.get.map { |c| Context.new omnifocus, c } end |
#all_projects ⇒ Object
806 807 808 809 810 |
# File 'lib/omnifocus.rb', line 806 def all_projects self.omnifocus.flattened_projects.get.map { |p| Project.new omnifocus, p } end |
#all_subtasks(task) ⇒ Object
81 82 83 |
# File 'lib/omnifocus.rb', line 81 def all_subtasks task [task] + task.tasks.get.flatten.map{|t| all_subtasks(t) } end |
#all_tasks ⇒ Object
85 86 87 88 89 |
# File 'lib/omnifocus.rb', line 85 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
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/omnifocus.rb', line 435 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
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/omnifocus.rb', line 393 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
372 373 374 375 376 377 378 379 380 381 |
# File 'lib/omnifocus.rb', line 372 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
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 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 |
# File 'lib/omnifocus.rb', line 260 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, :start_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
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/omnifocus.rb', line 324 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
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/omnifocus.rb', line 578 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
608 609 610 |
# File 'lib/omnifocus.rb', line 608 def cmd_review args print_aggregate_report live_projects end |
#cmd_schedule(args) ⇒ Object
383 384 385 386 387 388 389 390 391 |
# File 'lib/omnifocus.rb', line 383 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
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/omnifocus.rb', line 215 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
595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/omnifocus.rb', line 595 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
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/omnifocus.rb', line 347 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
824 825 826 827 |
# File 'lib/omnifocus.rb', line 824 def context name context = self.omnifocus.flattened_contexts[name].get rescue nil Context.new omnifocus, context if context end |
#create_missing_projects ⇒ Object
Create any projects in bug_db that aren’t in omnifocus, add under the nerd folder.
157 158 159 160 161 162 163 |
# File 'lib/omnifocus.rb', line 157 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
428 429 430 431 432 433 |
# File 'lib/omnifocus.rb', line 428 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
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/omnifocus.rb', line 492 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.}" end end end |
#fix_release_task_names(projs, tasks, skip) ⇒ Object
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/omnifocus.rb', line 516 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
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 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 |
# File 'lib/omnifocus.rb', line 532 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
317 318 319 320 321 322 |
# File 'lib/omnifocus.rb', line 317 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 |
#its ⇒ Object
:nodoc:
73 74 75 |
# File 'lib/omnifocus.rb', line 73 def its # :nodoc: Appscript.its end |
#live_projects ⇒ Object
812 813 814 815 816 |
# File 'lib/omnifocus.rb', line 812 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.
94 95 96 |
# File 'lib/omnifocus.rb', line 94 def make target, type, name, extra = {} target.make :new => type, :with_properties => { :name => name }.merge(extra) end |
#mechanize ⇒ Object
Returns the mechanize agent
148 149 150 151 |
# File 'lib/omnifocus.rb', line 148 def mechanize require 'mechanize' @mechanize ||= Mechanize.new end |
#nerd_projects ⇒ Object
Get all projects under the nerd folder
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/omnifocus.rb', line 101 def nerd_projects unless defined? @nerd_projects then @nerd_projects = omnifocus.folders["nerd"] begin @nerd_projects.get rescue make omnifocus, :folder, "nerd" end end @nerd_projects end |
#no_autosave_during ⇒ Object
854 855 856 857 858 859 |
# File 'lib/omnifocus.rb', line 854 def no_autosave_during self.omnifocus.will_autosave.set false yield ensure self.omnifocus.will_autosave.set true end |
#non_dropped_project ⇒ Object
802 803 804 |
# File 'lib/omnifocus.rb', line 802 def non_dropped_project its.status.eq(:dropped).not end |
#omnifocus ⇒ Object
77 78 79 |
# File 'lib/omnifocus.rb', line 77 def omnifocus @omnifocus ||= Appscript.app('OmniFocus').default_document end |
#prepopulate_existing_tasks ⇒ Object
Walk all omnifocus tasks under the nerd folder and add them to the bug_db hash if they match a bts_id.
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 |
# File 'lib/omnifocus.rb', line 119 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 |
#print_aggregate_report(collection, long = false) ⇒ Object
705 706 707 708 709 710 711 712 713 |
# File 'lib/omnifocus.rb', line 705 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 |
#print_details(h, long = false) ⇒ Object
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 |
# File 'lib/omnifocus.rb', line 782 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 |
#print_occurrence_table(h, p) ⇒ Object
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
# File 'lib/omnifocus.rb', line 753 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
829 830 831 832 |
# File 'lib/omnifocus.rb', line 829 def project name project = self.omnifocus.flattened_projects[name].get Project.new omnifocus, project if project end |
#regular_tasks ⇒ Object
840 841 842 |
# File 'lib/omnifocus.rb', line 840 def regular_tasks (its.value.class_.eq(:item).not).and(its.value.class_.eq(:folder).not) end |
#selected_tasks ⇒ Object
848 849 850 851 852 |
# File 'lib/omnifocus.rb', line 848 def selected_tasks window.content.selected_trees[regular_tasks].value.get.map { |t| Task.new self, t } end |
#top(hash, n = 10) ⇒ Object
254 255 256 257 258 |
# File 'lib/omnifocus.rb', line 254 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_tasks ⇒ Object
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.
170 171 172 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 |
# File 'lib/omnifocus.rb', line 170 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 task.completed.set false 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 task.completed.set true end when Array puts "Adding #{name} # #{bts_id}" next if $DEBUG title, url = *value make project, :task, title, :note => url else abort "ERROR: Unknown value in bug_db #{bts_id}: #{value.inspect}" end end end end |
#weekly(n = 1) ⇒ Object
305 306 307 308 309 310 311 |
# File 'lib/omnifocus.rb', line 305 def weekly n=1 { :unit => :week, :steps => n, :fixed_ => true, } end |
#window ⇒ Object
844 845 846 |
# File 'lib/omnifocus.rb', line 844 def window self.omnifocus.document_windows[1] end |