Rebuilding the TaskPaper PopClip Extension


#1

I’ve been working on adapting this code for a redo of the PopClip extension for TP3, but not having much luck parsing the input. Anyone see anything glaring that’s wrong in the input portion of the script? I can’t seem to pull the PopClip input which is stored in an env variable…

function run(input, parameters) {
ObjC.import('stdlib')
var selectedText = $.getenv('POPCLIP_TEXT')
var TaskPaper = Application('TaskPaper')
// Send it to TaskPaper Inbox
TaskPaper.documents[0].evaluate({
	script: TPContext.toString(),
	withOptions: {text: ("- " + selectedText) }
});
function TPContext(editor, options) {
    var outline = editor.outline;
    var inbox = outline.evaluateItemPath('//Inbox:')[0];
    var items = ItemSerializer.deserializeItems(options.text, outline, ItemSerializer.TEXTMimeType);

    if (!inbox) {
        inbox = outline.createItem('Inbox:');
        outline.root.insertChildrenBefore(inbox, outline.root.firstChild);
    }
    
    inbox.insertChildrenBefore(items, inbox.firstChild);
    
    return true;
}
}

Thanks,
Brad


#2

hopefully someone replies. :wink:


#3

I think it’s been updated now:


#4

noob question, how do you take that and make it an extension?

ty


#5

The compiled version is packaged up at:

https://pilotmoon.com/popclip/extensions/

https://pilotmoon.com/popclip/extensions/ext/TaskPaper.popclipextz


#6

This extension seems to add things as notes to TP rather than as new tasks. Am I understanding it wrong? Is there a bug?

However the extension does put the copied text as a note in my Inbox project.


#7

I guess that’s probably by design, but one could write such an extension in various ways.


#8

Looking at it more closely, the default extension simply puts the selected text, without modification, through the default TaskPaper parser. In other words, if the selection is prefixed with a hyphen, then it will come in as a task, but not otherwise. An advantage of this approach would be that you could bring in several selected lines, and get proper indentation/nesting of them in TaskPaper.

(I think, however, that the default extension is configured at the moment (by a gate-keeping regular expression (?s)^[\n\r]*[^\n\r]{1,300}[\n\r]*$) to respond only to single line selections)

The existing extension is written in php + JS, but an AppleScript + JS equivalent of what it is doing would be something like the code below.

It is only using the {popclip text} field, but PopClip can make a number of other fields available.
See the full list at:

If any of these fields look useful, then various alternative extensions, or an extension with some options, could perhaps be sketched out.

on run
    set strJS to "function TPContext(editor, options) {
    var outline = editor.outline;
    var inbox = outline.evaluateItemPath('//Inbox:')[0];
    var items = ItemSerializer.deserializeItems(options.text, outline, ItemSerializer.TEXTMimeType);
    
    if (!inbox) {
        inbox = outline.createItem('Inbox:');
        outline.root.insertChildrenBefore(inbox, outline.root.firstChild);
    }
    
    inbox.insertChildrenBefore(items, inbox.firstChild);
}"
    
    tell application "TaskPaper"
        set docs to documents
        if length of docs > 0 then
            set doc to front document
        else
            set doc to make new document
        end if
        activate
        tell doc
            set varResult to (evaluate script strJS with options ¬
                {|text|:"{popclip text}", urls:"{popclip urls}", titles:"{popclip url titles}"})
        end tell
    end tell
end run

#9

Thanks @complexpoint!!!


#10

Thank you Complex!!!


#11

Thank you for the explanation. Now that I understand how it’s supposed to work it all makes sense to me. Thanks for creating this PopClip extension. Very useful!


#12

I hope you are not offering credit to me :slight_smile:

I think perhaps it’s the work of @brokosz


#13

Ha, my bad! Thanks to @brokosz ! It’s very useful to have this script/extension to use.


#14

Hi

I downloaded the PopClip extension this morning after updating TP to version 265.

I’m getting an error when I use it:

Any suggestions?

Thanks

Bob


#15

The current build of TaskPaper has the application id “com.hogbaysoftware.TaskPaper3.direct”

whereas inside the popclip extension bundle the .plist file and tp.php script are both looking for either “com.hogbaysoftware.TaskPaper3” or “com.hogbaysoftware.TaskPaper.mac”

The trick will be to alert the supplier of Popclip that there is a new id in the field, and ask them to update their extension so that it can find the TaskPaper app.


#16

I just sent @pilotmoon a tweet requesting fix


#17

PopClip extension is working after recent update 9/28/2016 4:05 pm CDT.

Try:

https://github.com/pilotmoon/PopClip-Extensions/blob/master/extensions/TaskPaper.popclipextz?raw=true