-
-
Save stijlist/10074436 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
# tp-dailylog.rb - Log TaskPaper tasks completed on the current day to a Day One entry | |
# Brett Terpstra 2012 <http://brettterpstra.com> | |
# | |
# Run it with launchd at 11pm and forget about it | |
# | |
# Notes: | |
# * Uses `mdfind` to locate all .taskpaper files changed in the last day | |
# * Scans for @done(xxxx-xx-xx) tags in each line matching today's date | |
# * Does not alter TaskPaper files in any way | |
# * Does not require the Day One CLI tool | |
# * Only generates report if there are completed tasks found | |
# * It's configured to locate an iCloud-synced journal. | |
# If you use Dropbox or other, you'll want to just hardcode the path (comment line 23, edit `dayonepath` line 24) | |
# * To set the automatic Day One entries to starred, just change `starred = false` to true | |
require 'time' | |
require 'erb' | |
uuid = %x{uuidgen}.gsub(/-/,'').strip | |
datestamp = Time.now.utc.iso8601 | |
starred = false | |
dayonedir = %x{ls ~/Library/Mobile\\ Documents/|grep dayoneapp}.strip | |
dayonepath = "~/Library/Mobile\ Documents/#{dayonedir}/Documents/Journal_dayone/entries/" | |
template = ERB.new <<-XMLTEMPLATE | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Creation Date</key> | |
<date><%= datestamp %></date> | |
<key>Entry Text</key> | |
<string><%= entrytext %></string> | |
<key>Starred</key> | |
<<%= starred %>/> | |
<key>UUID</key> | |
<string><%= uuid %></string> | |
</dict> | |
</plist> | |
XMLTEMPLATE | |
today = Time.now().strftime('%Y-%m-%d') | |
files = `echo $STACKFILE $NEXTFILE`.split(' ') # there's probably a better way | |
projects = [] | |
files.each do |file| | |
if File.exists?(file.strip) | |
f = File.open(file.strip) | |
lines = f.read | |
f.close | |
project = "### " + File.dirname(file).gsub(/^.*?\/([^\/]+)$/,"\\1") + ":\n\n" | |
found_completed = false | |
lines.each do |line| | |
if line =~ /@done\(#{today}\)/ | |
found_completed = true | |
project += line.gsub(/@done\(.*?\)/,'').strip + "\n" | |
end | |
end | |
if found_completed | |
projects.push(project) | |
end | |
end | |
end | |
def e_sh(str) | |
str.to_s.gsub(/(?=["\\])/, '\\') | |
end | |
if projects.length > 0 | |
entrytext = "# Task report for #{today}\n\n" | |
projects.each do |project| | |
entrytext += project + "\n\n" | |
end | |
fh = File.new(File.expand_path(dayonepath+uuid+".doentry"),'w+') | |
fh.puts template.result(binding) | |
fh.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment