Created
November 22, 2012 05:27
-
-
Save ttscoff/4129534 to your computer and use it in GitHub Desktop.
Quick little CLI to make Reminders.app reminders
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 | |
# Quick little CLI to make Reminders.app reminders | |
# Requires 'amatch' and 'chronic' gems | |
# | |
# Pipe text in to create an attached note | |
# First text in note is the title | |
# An @ separates title from time, if there's no @, no date is set | |
# use @\d[hmd] to add time from the current date/time | |
# use "@tomorrow" or "@wednesday 3pm" to parse natural language | |
# use ! at the end to set high priority | |
require 'date' | |
require 'rubygems' | |
require 'appscript';include Appscript | |
require 'amatch';include Amatch | |
require 'chronic' | |
def parse_date(datestring) | |
days = 0 | |
if datestring =~ /^\+?(\d+)([hmd])?$/ # defaults to minutes without [hmd] | |
case $2 | |
when "h" then inc = (60 * 60 * 1 * $1.to_i) | |
when "d" then inc = (60 * 60 * 24 * $1.to_i) | |
else inc = (60 * $1.to_i) | |
end | |
newdate = Time.now + inc | |
else | |
newdate = Chronic.parse(datestring, {:context => :future, :ambiguous_time_range => 8}) | |
end | |
newdate | |
end | |
if STDIN.stat.size > 0 | |
note = STDIN.read | |
else | |
note = false | |
end | |
titlestring = ARGV.join(' ') | |
# check for trailing ! (flagged task) | |
flagged = titlestring.match(/\s*!$/).nil? ? 0 : 1 | |
titlestring.sub!(/\s*!$/,'') if flagged | |
name, date = titlestring.split("@") | |
name.strip! | |
date = date.nil? ? false : date.chomp! | |
remind_date = date.nil? ? false : parse_date(date) | |
rm = app('Reminders') | |
props = {} | |
props[:name] = name | |
props[:remind_me_date] = remind_date if remind_date | |
props[:priority] = flagged | |
props[:body] = note if note | |
list = rm.lists['Reminders'] | |
list.make(:new => :reminder, :with_properties => props) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment