Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Daily background logger to write completed TaskPaper tasks (system-wide) to a Day One entry
# tp-dailylog.rb - Log TaskPaper tasks completed on the current day to a Day One entry
# Brett Terpstra 2012 <>
# 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 =
starred = false
dayonedir = %x{ls ~/Library/Mobile\\ Documents/|grep dayoneapp}.strip
dayonepath = "~/Library/Mobile\ Documents/#{dayonedir}/Documents/Journal_dayone/entries/"
template = <<-XMLTEMPLATE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<key>Creation Date</key>
<date><%= datestamp %></date>
<key>Entry Text</key>
<string><%= entrytext %></string>
<<%= starred %>/>
<string><%= uuid %></string>
today ='%Y-%m-%d')
files = %x{mdfind 'kMDItemContentModificationDate >= "$" && kMDItemKind == "TaskPaperDocumentType"'}
projects = []
files.each do |file|
if File.exists?(file.strip)
f =
lines =
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"
if found_completed
def e_sh(str)
str.to_s.gsub(/(?=["\\])/, '\\')
if projects.length > 0
entrytext = "# Task report for #{today}\n\n"
projects.each do |project|
entrytext += project + "\n\n"
fh =".doentry"),'w+')
fh.puts template.result(binding)
Copy link

ghost commented Mar 16, 2012

The if condition projects.length always returns true, so even on days with no completed tasks, a header-only entry will be created in Day One. I changed the test to projects.length > 0 to avoid this. (In Ruby, zero does not evaluate to false)

Also, on my system the mdfind command above does not work. I can only imagine it has something to do with the locale on my machine. In my script I replaced the mdfind command with the following:

mdfind 'kMDItemContentModificationDate >= "$" && kMDItemKind == "TaskPaperDocumentType"'


Copy link

ttscoff commented Mar 17, 2012

Very nice, thanks for the fixes. I've updated this gist with both suggestions.


Copy link

ghost commented Mar 18, 2012

You are very welcome. I have had so much good use of the various scripts you have provided, so I am just happy to be able to contribute a tiny bit.


Copy link

craigeley commented Jan 8, 2014

Got this to work on Mavericks by changing line 48 to files.split("\n").each do |file| and line 50 to f =, encoding: 'UTF-8')


Copy link

matt-the-ogre commented Feb 8, 2014

I had to add lines = lines.split("\n") between lines 52 and 53 for this to work on my Mavericks installation. (After the f.close line.)
Otherwise I got ./tp-dailylog.rb:55:in 'block in <main>': undefined method 'each' for #<String:0x007fcd1b103c78> (NoMethodError)


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