Skip to content

Instantly share code, notes, and snippets.

Last active July 23, 2018 16:37
Show Gist options
  • Save craigeley/8301817 to your computer and use it in GitHub Desktop.
Save craigeley/8301817 to your computer and use it in GitHub Desktop.
This script looks for text files in a specific folder that include completed tasks ('@done') and timestamps, and then collects them into a daily log for the Day One journaling application. It works especially well when it's connected to IFTTT. See more details at
# SIFTTTER 1.5: An IFTTT-to-Day One Logger by Craig Eley 2014 <>
# Based on tp-dailylog.rb by Brett Terpstra 2012 <>
# Multiple Date Function by Paul Hayes 2014 <>
# Notes:
# * Uses `mdfind` to locate a specific folder of IFTTT-generated text files changed in the last day
# * The location of your folder should be hardcoded in line 67, and the location of your Day One in line 66
# * Scans leading timestamps in each line matching the selected dates
# * Does not alter text files in any way
# * Changes ampersand ('&') to 'and' so the script keeps running
# * Does not require the Day One CLI tool
# * Only generates report if there are completed tasks found
# * Compiles each day into a single Day One entry
# * It's configured to locate a Dropbox-synced journal, so
# * If you use iCloud you'll can just uncomment lines 64 and 65, and comment line 66
# * To set the Day One entries to starred, just change false to true on line 24
require 'time'
require 'erb'
require 'date'
require 'optparse'
starred = false
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><%= filename %>T04:58:00Z</date>
<key>Entry Text</key>
<string><%= entrytext %></string>
<<%= starred %>/>
<string>daily logs</string>
<string><%= uuid %></string>
options = {} do |opts|
opts.banner = "Usage: sifttter.rb [options]"
opts.on('-d', '--date DATE', 'Date to generate - Any parseable date string') { |v| options[:date] = v }
opts.on('-s', '--start START', 'Start date - Use with end to generate a range of dates') { |v| options[:start_date] = v }
opts.on('-e', '--end END', 'End date - Use with start to generate a range of dates') { |v| options[:end_date] = v }
if options[:start_date] && options[:end_date]
start_date = Date.parse(options[:start_date])
end_date = Date.parse(options[:end_date])
date_range = (start_date..end_date).map { |date| date }
date = options[:date] ? Date.parse(options[:date]) :
date_range = [date]
# dayonedir = %x{ls ~/Library/Mobile\\ Documents/|grep dayoneapp}.strip
# dayonepath = "~/Library/Mobile\ Documents/#{dayonedir}/Documents/Journal_dayone/entries/"
dayonepath = "/Users/USERNAME/Dropbox/Apps/Day\ One/Journal.dayone/entries/"
files = %x{mdfind -onlyin /Users/USERNAME/Dropbox/IFTTT -name '.txt' | grep -v -i daily | sort}
date_range.each do |date|
formatted_date = date.strftime('%B %d, %Y')
filename = (date + 1).strftime('%Y-%m-%d')
projects = []
files.split("\n").each do |file|
if File.exists?(file.strip)
f =, encoding: 'UTF-8')
lines =
# Uses filename as header for section, strips out filetype
project = "### " + File.basename(file).gsub(/^.*?\/([^\/]+)$/,"\\1").capitalize + "\n"
found_completed = false
lines.each_line do |line|
if line =~ /&/
line.gsub!(/[&]/, 'and')
if line =~ /#{formatted_date}/
found_completed = true
# Removes formatted date and @done pattern from entry
project += line.gsub(/@done/,'').gsub(/#{formatted_date}.../,'').strip + "\n"
if found_completed
if projects.length > 0
entrytext = "# Things done on #{formatted_date}\n\n"
uuid = %x{uuidgen}.gsub(/-/,'').strip
projects.each do |project|
entrytext += project.gsub(/.txt/, ' ') + "\n"
file = "#{dayonepath}#{uuid}.doentry"
fh =,'w+')
fh.puts template.result(binding)
puts "Entry Generated for #{formatted_date}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment