ArchiveAllOrSelectedDoneEntries


Outdated!!!

This information is for TaskPaper 2 which is old and outdated. TaskPaper 3 is the current version of TaskPaper. For TaskPaper 3 support please visit the support forums.


TaskPaper is great! However, there has always been something bothering me: why is it not possible to selectively archive done items in addition to the standard behaviour to process all entries in a batch?

AppleScript to the rescue :) Either copy, paste & save the following first release script to a file named "Archive All or Selected Done Entries.applescript" or download the Latest Version 111106-3 from the cloud.

To complete the change of TaskPaper's behaviour regarding the command "Archive Done Tasks" I have assigned the original shortcut CMD-SHIFT-D to the script in FastScripts. The result is an enhanced and even more powerful application!

(*
 * Script: Archive All or Selected Done Entries
 *
 * Version: 111104-4
 *
 * This script does target TaskPaper for Mac (C) Hog Bay Software: www.hogbaysoftware.com/products/taskpaper and is based on some key concepts taken from the script "Archive TaskPaper entries tagged A to project B" dated 2009-12-27 Version 1.0: http://www.hogbaysoftware.com/wiki/ArchiveEntriesTaggedXtoProjectY.
 *
 * The following main features have been implemented and / or enhanced:
 *
 * - tagging of all or selected done entries with @project, excluding already pre-tagged and / or archived items
 * - setting of the full containers' path as the value for the tag, with no depth limit to be taken into account
 * - moving the processed entries to the designated "logbook" for archiving purposes
 *
 * Do the following to select:
 *
 * - all active done entries : position the cursor anywhere on an item with no done tag
 * - a single active done entry : position the cursor anywhere on the done item to archive
 * - multiple active done entries : CMD double click anywhere on the first done item and repeat for all others while keeping the CMD key pressed to archive in one batch
 *
 * In addition it removes existing "tagsToDelete", if the flag "deleteTags" is set to true.
 *
 * Feel free to edit the respective script properties in the Public User Interface section according to your needs.
 *
 * History:
 *
 * - 04.11.2011: Documenting - added the description for the different selection methods.
 * - 04.11.2011: Defensive coding - made sure that the designated archive project does exist.
 * - 04.11.2011: Performance refactoring - moved the archiving of entries and the optional deletion of user defined tags out of the processing block.
 * - 04.11.2011: Initial release.
 *
 * Copyright (C) 2011 Stefano F. Rausch. All rights reserved.
 *)

-- Public User Interface

property logbook : "Archive"

property deleteTags : true
property tagsToDelete : {"day", "someday", "today", "week"}

-- Private Top Level Script Code

tell application "TaskPaper"
    tell front document

        if not (exists project logbook) then
            make project with properties {name:logbook} at end
        end if

        set archive to project named logbook

        -- Get done entries.

        set selectedEntries to get selected entries

        if (count selectedEntries) = 1 and not (exists tag named "done" of item 1 of selectedEntries) then
            set selectedEntries to get every entry
        end if

        set doneEntries to {}

        repeat with |entry| in selectedEntries
            tell |entry|

                if not (container is archive) and (exists tag named "done") then
                    set end of doneEntries to |entry|
                end if

            end tell
        end repeat

        -- Add project tag.

        repeat with |entry| in doneEntries
            tell |entry|

                if not (exists tag named "project") then
                    set containerPath to ""

                    -- Get containers' path.

                    if (exists container) then
                        set |container| to container
                        set containerPath to name of |container|

                        repeat while (exists container of |container|)
                            set |container| to container of |container|
                            set containerPath to (name of |container|) & " / " & containerPath
                        end repeat
                    end if

                    -- Tag.

                    make tag with properties {name:"project", value:containerPath} at end
                end if

            end tell
        end repeat

        -- Archive entries.

        repeat with |entry| in doneEntries
            tell |entry|

                move to beginning of entries of archive

            end tell
        end repeat

        -- Remove tags.

        if (deleteTags is true) then
            repeat with |entry| in doneEntries
                tell |entry|

                    repeat with |tag| in tagsToDelete
                        if (exists tag named |tag|) then
                            delete tag named |tag|
                        end if
                    end repeat

                end tell
            end repeat
        end if

    end tell
end tell

-- End of Script

Happy Getting Things Done!

Stefano F. Rausch