Skip to content

Instantly share code, notes, and snippets.

@jverkoey
Forked from byingyang/gist:181626
Last active January 26, 2018 15:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jverkoey/6983934 to your computer and use it in GitHub Desktop.
Save jverkoey/6983934 to your computer and use it in GitHub Desktop.
Update for Things 2.2's use of Projects instead of Areas.
# 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