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.
This script makes it possible to archive entries with a designated tag to a Project of the user's choice. It is similar in intent to TaskPaper's built-in "Archive Done Tasks" command. The script was originally written for a user who wished to abandon some tasks and projects by archiving them to a project named "Abandoned". The script might also be helpful to someone who wants to use special tags for a limited time; archive all entries with these tags; and then delete the tags afterwards.
There are three options to set at the top of the script:
• The name of the archive tag (Default: "abandoned")
• The name of the archive project (Default: "Abandoned"
• Whether the archive tag is deleted after an entry is archived (Default: true)
Thee archive project will be created if it does not already exist.
If an archived entry is contained in other entries, the script creates a descriptive tag "project()" with a value that shows the containing entries. This tag is modeled after the one created by the "Archive Done Tasks" command, with one difference. The built-in command shows projects which contain the archived entry. This script shows all enclosing entries (up to six levels), whether they are projects or tasks (or notes, for that matter). The difference can be seen with the following example of a single project with one task and a subtask of the first task.
➲ A
– task one
-subtask @abandoned
With the the "Archive Done Tasks" command, the archived "subtask" would be shown with the tag "@project(A). The current script will write the descriptive tag as: "@project(A/task one)".
The script can be downloaded here.
This is the content:
(* Archive TaskPaper entries tagged X to project Y
2009-12-27
Version 1.0
Steve Samuels
sjsamuels@gmail.com
Archive entries with a designated tag to a designated project.
Set the tag and project in the first two lines of the script.
If the designated project does not exist, it will be created.
By default the designated tag is deleted after the entry is moved.
To change this, set the "delete_tag_after_archive" property to "false"
*)
property archive_tag : "abandoned"
property archive_Project : "Abandoned"
property delete_tag_after_archive : true
tell application "TaskPaper"
tell front document
if not (exists project archive_Project) then
make project with properties {name:archive_Project} at end
end if
set _use to {} --list to hold entries not previously archived
set _all to id of every entry
set _at to {}
--First find all entries with archive tag
repeat with x in _all
if exists tag named archive_tag of entry id x then
set _at to _at & x
end if
end repeat
-- If delete_tag_after_archive is false, some tagged entries
-- are in the archive folder. The list _use constructed next
-- holds entries not yet archived.
set _eca to entire contents of entry archive_Project
set _ida to {}
repeat with y in _eca
set _ida to _ida & id of y
end repeat
repeat with w in _at
if w is not in _ida then
set _use to _use & w
end if
end repeat
-- Process tagged Entries; _mv is a temporary tracking tag
repeat with _c0 in _use
if not (exists container of entry id _c0) then
set _ec0 to entire contents of entry id _c0
repeat with k in _ec0
make tag at end of k with properties {name:"_mv"}
end repeat
if entry type of entry id _c0 is project type then
move project id _c0 to beginning of entries of project archive_Project
else
move entry id _c0 to beginning of entries of project archive_Project
end if
else --If the entry is contained in other entries, add "project" tag to show these.
set _tagname to my gettag(_c0) -- <-function at end of script to construct the tag
if not (exists tag named "_mv" of entry id _c0) then
make tag at end of entry id _c0 with properties {name:"project", value:_tagname}
set _ec0 to entire contents of entry id _c0
repeat with k in _ec0
make tag at end of k with properties {name:"_mv"}
end repeat
if not (exists tag named "_mv" of entry id _c0) then
move entry id _c0 to beginning of entries of project archive_Project
end if
end if
end if
end repeat
--Delete temporary tag and, optionally, the archive_tag
set _ec to entire contents of entry archive_Project
repeat with x in _ec
set _ttags to (tags of x)
repeat with w in _ttags
if name of w is "_mv" then
delete w
end if
end repeat
set _tags to (tags of x)
repeat with z in _tags
if delete_tag_after_archive is true then
if name of z is archive_tag then delete z
end if
end repeat
end repeat
end tell
end tell
-- Function to add names of nested containers (6 deep) to "Project" tag
on gettag(_c0)
tell application "TaskPaper"
tell front document
set tagp to ""
if (exists container of entry id _c0) and (name of container of entry id _c0 is not archive_Project) then
set _c1 to id of container of entry id _c0
if not (exists tag named archive_tag of project _c1) then
set tagp to name of entry id _c1
end if
if (exists container of entry id _c1) and (name of container of entry id _c1 is not archive_Project) then
set _c2 to id of container of entry id _c1
if not (exists tag named archive_tag of project _c2) then
set tagp to name of entry id _c2 & "/" & tagp
end if
if (exists container of entry id _c2) and (name of container of entry id _c2 is not archive_Project) then
set _c3 to id of container of entry id _c2
if not (exists tag named archive_tag of project _c3) then
set tagp to name of entry id _c3 & "/" & tagp
end if
if (exists container of entry id _c3) and (name of container of entry id _c3 is not archive_Project) then
set _c4 to id of container of entry id _c3
if not (exists tag named archive_tag of project _c4) then
set tagp to name of entry id _c4 & "/" & tagp
end if
if (exists container of entry id _c4) and (name of container of entry id _c4 is not archive_Project) then
set _c5 to id of container of entry id _c4
if not (exists tag named archive_tag of project _c5) then
set tagp to name of entry id _c5 & "/" & tagp
end if
if (exists container of entry id _c5) and (name of container of entry id _c4 is not archive_Project) then
set _c6 to id of container of entry id _c5
if not (exists tag named archive_tag of project _c6) then
set tagp to name of entry id _c6 & "/" & tagp
end if
end if
end if
end if
end if
end if
end if
end tell
end tell
return tagp
end gettag