-
-
Save jverkoey/6983934 to your computer and use it in GitHub Desktop.
Update for Things 2.2's use of Projects instead of Areas.
This file contains 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
# format: | |
# -------------- | |
# date (mm/dd/yy) | |
# assignment | |
# assignment | |
# ... | |
# | |
# date | |
# assignment | |
# ... | |
# | |
# Command line usage: | |
# ruby thingsimport.rb <project name> <filename> | |
require 'rubygems' | |
require 'appscript' | |
require 'date' | |
class Date | |
def to_gm_time | |
to_time(new_offset, :gm) | |
end | |
def to_local_time | |
to_time(new_offset(DateTime.now.offset - offset + 1), :local) | |
end | |
private | |
def to_time(dest, method) | |
#Convert a fraction of a day to a number of microseconds | |
usec = (dest.sec_fraction * 60 * 60 * 24 * (10**6)).to_i | |
Time.send(method, dest.year, dest.month, dest.day, dest.hour, dest.min, | |
dest.sec, usec) | |
end | |
end | |
project = ARGV[0] | |
file = ARGV[1] | |
get_date = true | |
date = nil | |
File.open(file).readlines.each do |line| | |
if line != "\n" | |
if get_date | |
date = DateTime.parse(line.chomp).to_local_time | |
get_date = false | |
else | |
Appscript.app('Things').projects[project].make(:new => :to_do, :with_properties => {:name => line.chomp, :due_date => date}) | |
end | |
else | |
get_date = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment