Created
November 24, 2008 23:36
-
-
Save tommorris/28696 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'xml' | |
| class Tasks | |
| end | |
| class Things | |
| def initialize(filename = "/Users/" + `whoami`.strip + "/Library/Application\ Support/Cultured\ Code/Things/Database.xml") | |
| @doc = LibXML::XML::Document.file filename if File.exists? filename | |
| end | |
| def get_inbox | |
| @doc.find("//object[@type='TODO'][relationship/@idrefs='z118']/attribute[@name='title'][@type='string']/text()").to_a.reverse | |
| end | |
| def get_next_actions | |
| @doc.find("//object[@type='TODO'][relationship/@idrefs='z108']/attribute[@name='title'][@type='string']/text()").to_a.reverse | |
| end | |
| def add(string) | |
| objectid = @doc.find("//nextObjectID")[0] | |
| objectid.content = (objectid.children[0].to_s.to_i + 1).to_s | |
| objectref = "z" + objectid.content.to_s | |
| # now get the focus object and append a reference | |
| focusobject = @doc.find("//object[@type='FOCUS'][@id='z118']/relationship[@name='focustodos']/@idrefs")[0] | |
| focusobject.value = focusobject.value + " " + objectref | |
| database = @doc.find("/database")[0] | |
| objectnode = LibXML::XML::Node.new("object") | |
| objectnode['type'] = "TODO" | |
| objectnode['id'] = objectref.to_s | |
| focustype = LibXML::XML::Node.new("attribute") | |
| focustype['name'] = "focustype" | |
| focustype['type'] = "int32" | |
| focustype.content = "1" | |
| objectnode.child_add focustype | |
| focuslevel = LibXML::XML::Node.new("attribute") | |
| focuslevel['name'] = "focuslevel" | |
| focuslevel['type'] = "int16" | |
| focuslevel.content = "0" | |
| objectnode.child_add focuslevel | |
| # datemodified | |
| # datecreated | |
| # title | |
| # index | |
| # identifier | |
| # compact | |
| # rel-parent | |
| # rel-author | |
| # rel-delegate | |
| # rel-focus | |
| # rel-recurrenceinstance | |
| # rel-recurrencetemplate | |
| # rel-scheduler | |
| # rel-syncdata | |
| # rel-children | |
| # rel-tags | |
| # rel-reminderdates | |
| database.child_add objectnode | |
| return @doc.to_s | |
| end | |
| end | |
| qry = nil | |
| unless ARGV[0].nil? | |
| qry = ARGV[0].strip | |
| end | |
| things = Things.new | |
| if qry.class != NilClass | |
| if qry == "--inbox" or qry == "-i" | |
| things.get_inbox.each { |val| puts "> #{val}" } | |
| elsif qry.length != 0 | |
| things.add ARGV.join | |
| end | |
| else | |
| things.get_next_actions.each { |val| puts "> #{val}" } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment