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 is a utility function to get the Project tag associated with an entry. You pass it an entry, and it returns a Project tag like the Archive Done Tasks (e.g. @project(parent / child)). In theory, it works with an unlimited number of nested entries, but it was only tested up to eight.

on getProjectTag(anEntry)
    tell the front document of application "TaskPaper"
        set project_list to {}
        repeat while (exists containing project of anEntry)
            set anEntry to the containing project of anEntry
            copy the name of anEntry to beginning of project_list
        end repeat
        if (count of project_list) is 0 then
            -- example output: ""
            -- don't return anything since the entry isn't contained by a project. 
            -- this seems better than "@project()"
            set output to ""
            -- example output: "project(project1 / project2)" 
            -- just like the built-in Archive Done Tasks behavior
            set prevTIDs to text item delimiters of AppleScript
            set text item delimiters of AppleScript to " / "
            set output to ("project(" & project_list as string) & ")"
            set text item delimiters of AppleScript to prevTIDs
        end if
    end tell
    return output
end getProjectTag

Below is a short example of how to use it. It does NOT need to be in the same tell statement as your other code.

tell application "TaskPaper"
    -- a simple example to illustrate how to call it
    -- my getProjectTag()
    display dialog my getProjectTag(get selected entry)
end tell