Created
September 6, 2009 03:02
-
-
Save byingyang/181626 to your computer and use it in GitHub Desktop.
Script to batch import tasks into the "Things" app by Cultured Code
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 | |
# ... | |
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 | |
area = 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').areas[area].make(:new => :to_do, :with_properties => {:name => line.chomp, :due_date => date}) | |
end | |
else | |
get_date = true | |
end | |
end |
The expected format is:
2012-12-30
task title
another task title
2012-12-31
and so on
And so forth
(as noted in the comments)
Also, if you have issues running this in Mac OS X, it may be due to multiple versions of Ruby installed. In this case, explicitly run the version that has gems installed. Find this out by running "gem environment" and running the Ruby that is installed in that folder. Hope this helps someone!
I've updated this to work with Things 2.2 as of October 14, 2013 in my fork:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a script that will import tasks from a text file into the Things program for OS X by Cultured Code. Depends on the rb-appscript gem.