Created
May 13, 2021 03:31
-
-
Save craigeley/648a9d2fcebb590ab3bd85fdceae9859 to your computer and use it in GitHub Desktop.
A script that finds tasks in Things 3 that were completed today and formats them as a Markdown list for Day One
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 | |
# -*- coding: utf-8 -*- #specify UTF-8 (unicode) characters | |
require 'time' | |
tasktext = %x{ osascript <<APPLESCRIPT | |
set theDate to date string of ((current date)) | |
tell application "Things3" | |
set output to "" | |
repeat with toDo in (to dos whose status is completed) of list "Logbook" | |
set toDoName to name of toDo | |
set toDoDate to completion date of toDo | |
set toDoTime to time string of toDoDate | |
set toDoDone to date string of toDoDate | |
if toDoDone is equal to theDate then | |
if project of toDo is missing value then | |
set toDoTag to name of area of toDo | |
else | |
set toDoTag to name of project of toDo | |
end if | |
set output to output & toDoDate & " @ " & toDoName & " @" & toDoTag & linefeed | |
end if | |
end repeat | |
return output | |
end tell | |
APPLESCRIPT} | |
taskarray = [] | |
tagtext = "Tasks Completed on " + Time.now.strftime("%B %d") + "\n\n" | |
tasktext.strip.each_line do |line| | |
donetime, task, category = line.split(/\@/) | |
donetime = Time.parse(donetime).strftime("%l:%M%P") | |
inject = { :name => task.strip, :time => donetime.strip, :category => category.strip } | |
taskarray.push(inject) | |
end | |
taskarray = taskarray.sort_by {|h| [h[:category],h[:time]]} | |
uniq_tags = taskarray.map { |e| e[:category] }.uniq | |
uniq_tags.each do |tagger| | |
tagtext += "\n### #{tagger}\n" | |
taskarray.each do |unit| | |
if unit.has_value?(tagger) | |
tagtext += "- " + unit[:time] + " - " + unit[:name] + "\n" | |
end | |
end | |
end | |
`dayone2 new "#{tagtext}"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment