Skip to content

Instantly share code, notes, and snippets.

@byingyang
Created September 6, 2009 03:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save byingyang/181626 to your computer and use it in GitHub Desktop.
Save byingyang/181626 to your computer and use it in GitHub Desktop.
Script to batch import tasks into the "Things" app by Cultured Code
# 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
@byingyang
Copy link
Author

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.

@mmmnorthmark
Copy link

The expected format is:

2012-12-30
task title
another task title

2012-12-31
and so on
And so forth

@mmmnorthmark
Copy link

(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!

@jverkoey
Copy link

I've updated this to work with Things 2.2 as of October 14, 2013 in my fork:

https://gist.github.com/jverkoey/6983934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment