Hook to a specific task

Hook allows you to link “items of content” on your Mac so that you can quickly hop between them using a LaunchPad / Alfred type interface. For instance you can link a file with an email with a website. These scripts allow you to link these things to an individual TaskPaper task. You can jump directly to any of these, or create a new (for example) nvUltra document for this task.

The Hook script and KM Macros, with instructions are on my Github Page.

I’m sure that these could be written to not require KM, but my skills at bridging Applescript to Javascript are not up to the task. If anyone wants to help out, I’d be very happy.

1 Like

Hi, are you asking about an alternative route to activating/following links to TaskPaper items ?

One general route would be to write a custom url handler.

A couple of quick questions:

  • are you not indenting tasks under projects with tabs ? Your PNG suggests that you may be relying on a syntax from some years ago, when unindented tasks would be parsed as children of a preceding project at the same level of indent. (TaskPaper3 folding and search syntax relies on consistently tab-indented outlines)
  • Do the links you are building rely on task IDs persisting between sessions ?

(@jessegrosjean may be able to advise us on the extent to which IDs persist, but an alternative is to build links which use search paths)

FWIW if you wanted to test the persistance of TaskPaper item IDs across the closing and reopening of files, you could try running (in Script Editor or similar) this snippet, which just displays and copies the ids in the front document.

(Copy – in full – the source below, behind the JS Source disclosure triangle, all the way down to the final two lines, which are:

    return main()
})();

JS Source
(() => {
    'use strict';

    ObjC.import('AppKit');

    // Display and copy a list of the IDs in the 
    // front document in TaskPaper 3.

    // main :: IO ()
    const main = () => {
        const
            docs = Application('TaskPaper')
            .documents;
        return 0 < docs.length ? (
            copyText(
                alert('IDs in front document')(
                    docs[0].evaluate({
                        script: `${
                            editor => editor.outline.toString()
                        }`
                    })
                )
            )
        ) : 'No documents open in TaskPaper 3';
    };


    // ------------------- JXA CONTEXT -------------------

    // alert :: String => String -> IO String
    const alert = title =>
        s => {
            const sa = Object.assign(
                Application('System Events'), {
                    includeStandardAdditions: true
                });
            return (
                sa.activate(),
                sa.displayDialog(s, {
                    withTitle: title,
                    buttons: ['Cancel', 'Copy'],
                    defaultButton: 'Copy',
                    withIcon: sa.pathToResource(
                        'TaskPaper.icns', {
                            inBundle: 'Applications/TaskPaper.app'
                        })
                }),
                s
            );
        };

    // copyText :: String -> IO String
    const copyText = s => {
        const pb = $.NSPasteboard.generalPasteboard;
        return (
            pb.clearContents,
            pb.setStringForType(
                $(s),
                $.NSPasteboardTypeString
            ),
            s
        );
    };

    return main()
})();

Other threads in which you might find odds and ends include:

TaskPaper 3 example :: links preserving filter state - Share your Hook scripts - Hook Productivity Forum

Linking to items - TaskPaper - Hog Bay Software Support

1 Like

For those interested in the more general usage of Hook and TaskPaper, I’ve published How to Turn a TaskPaper File into a Project Information Hub – Hook. (I’m a member of CogSci Apps, Hook’s dev, and an avid user of TaskPaper.)

Thanks @complexpoint for the various scripts and pointers.

There’s a cross-post here: Hook to an individual task in TaskPaper - Share your Hook scripts - Hook Productivity Forum.

It may be worth annotating the cross-post to the effect that a scheme based on Task IDs could prove frustrating – a Taskpaper file is plain text, and the IDs only last for one editing session.

If a TaskPaper file is closed and reopened, those id-based links to specific tasks will, unfortunately, fail, as each task will have a new id in the editor.

Thanks for the reply

No, this generates its own IDs which are stored in the file because internal ones, as you say, change between sessions.

Re tab - sorry yes, this was quickly thrown together for a screenshot.

2 Likes