Creating tasks from TaskPaper string on clipboard


Say I have a tagged TaskPaper task on my clipboard, is there a way to create an OF task from that, using AppleScript (or, failing that, black magic)? I know that pasting into OF will work, but I’m looking for something I can automate and trigger with a keyboard shortcut. I’ve tried this (and variations on it) but I end up with the full string in the task name, rather than the tags getting parsed as metadata.

set theTask to the clipboard
tell application "OmniFocus"
	tell default document
		set theProject to first flattened project where its name = "Ham"
		tell theProject to make new task with properties {name:theTask}
	end tell
end tell

Any idea how to make this work? Also, I noticed OF doesn’t handle @project tags from TP. Is there any way to specify a project in the TP string?


I decided to try this JS solution which works better, though it’s not ideal as it changes the Perspective in the focused window. Is there any way to add the task while remaining in the current Perspective?

'use strict';
(function run() { 
    var app = Application.currentApplication()
    app.includeStandardAdditions = true
    var kme = Application("Keyboard Maestro Engine");

    var TaskPaperURL = "omnifocus:///paste?target=/task/foo"

I am guessing but if you can paste the clipboard correctly can you not just set up a KeboardMaestro shortcut to create a new task and paste the content of the clipboard into it?

I may have been doing it wrong, but I was ending up with the entire TP string as a task. The tags weren’t being parsed into task metadata.

I’ve managed to get it working the way I want, although it’s very kludgy. I copy the TP task and run a KM macro that tags it in the way I want, then runs this Applescript:

tell application "OmniFocus"
    tell the default document
        make new document window with properties {perspective name:"Foo"}
        activate "OmniFocus"
    end tell
end tell

and then the JS above, followed by this AS:

tell application "OmniFocus" to close (get window 1)

This creates a new window with the Perspective “Foo”, adds the task and then closes the window. Hey, it’s not pretty but it works. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.