UnarchiveNotDoneTasks

This script reverses the actions of TaskPaper's standard menu item "Archive Done Tasks". Specifically, in the front document, it moves each task in the "Archive" project that does not have a @done tag, back to the project specified by the value of the @project tag. If the original project does not exists, a new project with that name is created at the beginning of the document. The project tag is stripped from the task. If the task does not have a @project tag, the task is moved to the beginning of the document. WARNING: This will not work properly if there are parentheses in the name of a project.

tell application "TaskPaper"
tell front document

    if (exists project "Archive") then
        set archiveProject to project "Archive"
        set entryCount to count entries of archiveProject

        if entryCount is greater than 0 then
            set theEntry to last entry of archiveProject

            repeat while theEntry is not (missing value)
                set nextEntry to previous sibling of theEntry
                if not (exists (tag named "done" of theEntry)) then
                    if exists (tag named "project") of theEntry then
                        set originalProject to value of tag "project" of theEntry
                        if not (exists (project originalProject)) then
                            make new project with properties {name:originalProject} at beginning
                        end if --not (exists (project originalProject)) then
                        delete tag named "project" of theEntry
                        move theEntry to front of entries of project originalProject
                    else
                        move theEntry to front of entries
                    end if --exists (tag named "project"
                end if --not (exists (tag named "done" of each)) then
                set theEntry to nextEntry
            end repeat --while theEntry is not (missing value)

        end if --entryCount > 0

    end if --(exists project "Archive")

end tell --front document
end tell --application "TaskPaper"