Skip to content

Instantly share code, notes, and snippets.

@johnelm
Forked from mreidsma/ArchiveandLogDone.scpt
Created July 18, 2012 02:13
Show Gist options
  • Select an option

  • Save johnelm/3133645 to your computer and use it in GitHub Desktop.

Select an option

Save johnelm/3133645 to your computer and use it in GitHub Desktop.

Revisions

  1. @mreidsma mreidsma created this gist Apr 17, 2012.
    59 changes: 59 additions & 0 deletions ArchiveandLogDone.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    -- Archive completed Taskpaper tasks to Google Calendar with ifttt.com
    -- First, set up the following recipe at ifttt.com to add completed tasks to your calendar:
    -- http://ifttt.com/recipes/30256
    --
    -- Then use this Applescript to archive tasks. Mail.app needs to have the default account match your ifttt.com email
    -- Let me know if you have any questions: [email protected] or @mreidsma


    set archivedTasks to ""

    tell application "TaskPaper"
    tell front document

    -- This next section from Stefano F. Rausch's Archive Entries Applescript
    -- http://www.hogbaysoftware.com/wiki/ArchiveAllOrSelectedDoneEntries

    -- Make sure there is an archive project
    if not (exists project "Archive") then
    make project with properties {name:"Archive"} at end
    end if

    set archive to project named "Archive"

    -- This whole function is from Brett Terpstra's excellent Taskpaper to DayOne script
    -- http://brettterpstra.com/log-taskpaper-archives-to-day-one/

    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 & "Tasks: " & (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

    -- Check to see if there were any completed tasks
    if archivedTasks is not "" then
    -- Send mail to ifttt to archive to calendar
    tell application "Mail"
    set theNewMessage to make new outgoing message with properties {subject:"Completed #task", content:archivedTasks, visible:false}
    tell theNewMessage
    make new to recipient at end of to recipients with properties {address:"[email protected]"}
    send
    end tell
    end tell
    end if