Skip to content

Instantly share code, notes, and snippets.

@judismith
Created August 10, 2012 16:36
Show Gist options
  • Save judismith/3315418 to your computer and use it in GitHub Desktop.
Save judismith/3315418 to your computer and use it in GitHub Desktop.
AppleScript to create Day One entry for hours logged in TaskPaper - Based on the AppleScript from Brett Terpstra to log TaskPaper completed tasks to Day One. This script does both
set archivedTasks to ""
set hoursEntries to ""
tell application "TaskPaper"
tell front document
-- don't care which file your log entry came from?
-- comment the next line out
set archivedTasks to "## " & name & return
set hoursEntries to "## " & name & ": Hours" & return
repeat with _task in search with query "project != Archive and @done"
if entry type of _task is not project type then
-- remove common tags that won't matter after archiving
repeat with _tag in {"na", "next", "priority", "waiting"}
if exists (tag named _tag of _task) then delete tag named _tag of _task
end repeat
-- if there's no project tag on the task,
-- add the task's current project as a tag
if not (exists (tag named "project" of _task)) then
tell _task to make tag with properties {name:"project", value:(name of containing project of _task as rich text)}
end if
-- append the full text of the entry, including tags, to our log
set archivedTasks to archivedTasks & (text line of _task)
-- archive it
move entry id (id of _task) to beginning of entries of project "Archive"
end if
end repeat
repeat with _task in search with query "project != Archive and @hours"
if entry type of _task is not project type then
-- if there's no project tag on the task,
-- add the task's current project as a tag
if not (exists (tag named "project" of _task)) then
tell _task to make tag with properties {name:"project", value:(name of containing project of _task as rich text)}
end if
-- append the full text of the entry, including tags, to our log
set hoursEntries to hoursEntries & (text line of _task)
-- archive it
move entry id (id of _task) to beginning of entries of project "Archive"
end if
end repeat
end tell
end tell
-- send the accumulated results to Day One via the command line tool
-- http://dayoneapp.com/faq/#commandlineinterface
-- You'll need to run `ln -s "/Applications/Day One/Day One.app/Contents/MacOS/dayone" /usr/local/bin/dayone` to have it accessible at this path
do shell script "echo " & (quoted form of archivedTasks) & "|tr -d \"\\t\"|/usr/local/bin/dayone new"
do shell script "echo " & (quoted form of hoursEntries) & "|tr -d \"\\t\"|/usr/local/bin/dayone new"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment