Implementation Details for OmniFocus 2.14 Automation

Try this:

‘omnifocus://x-callback-url/paste?x-success=omnifocus:///context/TEST&target=task/ERRANDS’

You use an “&” when you have multiple parameters. The “?” is only used once in any URL.

Unfortunately, that was a typo on this forum, and not in the URL code.

Still can’t get this to work. I trimmed the URL down to

omnifocus://x-callback-url/paste?x-success=omnifocus:///context/TEST&target=/context/TEST

And it still returns INVALID URL

In fact, so does

omnifocus://x-callback-url/paste?x-success=omnifocus:///context/TEST

Is it possible that /paste doesn’t work with x-success?

I added a context called Test and tapped the second URL. It worked.

I would guess the first one failed because of this: `&target=/context/TEST``. If I understand correctly, you can’t use a context as a target.

My second guess would be that your content is malformed.

The full URL being this:

omnifocus://x-callback-url/paste?x-success=omnifocus:///context/TEST&target=task/ERRANDS&content=TASKPAPER

Make sure you’re URL encoding TASKPAPER here. I just tried creating a test task with this and it worked fine.

Got it to work. There was a typo somewhere, and I just couldn’t see it. So i started over using a copy of the URL that worked without the callback, and retyped it all carefully. Bingo.

Thanks for your patient and persistent help.

1 Like

Tutorial was very good and even it alone made the cost of the video worthwhile .

I’ve been using my templates on iOS for some time - even creating slightly differing editorial actions to ensure different templates go into different folders, and using launchpad to instigate with a click.

All is good.

My big fly in the ointment is that I’ve got some taskpaper templates that I want to use on OSX, and I cannot. I can paste in a taskpaper template well enough, but the «fields» do not give rise to prompts that I can use.

I want to use the same templates (stored in dropbox) whichever platform.

Has anyone a solution for using the templates that work in iOS/editorial on OSX?

In an ideal world, I’d just like to tell iOS OF and OSX OF where my templates were, and then have it ‘just work’…maybe next update? (hint hint)

I have the following bit of python code.

  1. I would like to be able to run with a click
  2. I would like to remove the cut and paste at the end.

Updated as I wanted a clean exit for the ‘exit’ choice.
Updated again so that I could see the fields before being prompted, and also to output the template even if there are no fields to substitute

To use, change the template directory as needed, then run in python3.

#encoding: utf-8
from os import listdir, chdir, getcwd
from os.path import isfile, join
import re
import codecs


# Change this as needed
template_dir = "/Users/mark/Dropbox/Apps/Writing/Omnifocus Templates"
template_ext = ".taskpaper"




ext_len=-len(template_ext)
def inputNumber(message,max):
        while True:
                valid = False
                while ( not valid ):
                        try:
                                userInput = int(input(message))
                        except ValueError:
                                print ("Type a number")
                                continue
                        else:
                                valid = (0 <= userInput <= max )
                                if valid :
                                        return userInput
                                else:
                                        print("Choose from above options")
                        


old_dir = getcwd()

try:
        chdir(template_dir)
        dirs = listdir(getcwd())
        print("\n"+"Here are the templates that you have available:"+"\n")
        n=0
        filelist = []
        for file in dirs:
                # Only show taskpaper files
                if template_ext in file:
                        # Remove the file extension
                        file = file[:ext_len]
                        print(str(n).rjust(4) + ".   " + file)
                        filelist.append(file)
                        n += 1
        print("\n" + str(n).rjust(4) + ".   Exit")
        choice = inputNumber("\n"+"Which template? : ",n)
        if (choice<n):
                filechoice = filelist[choice] + template_ext
                print("\n" + "Using template " + filechoice)
                f = codecs.open(filechoice,encoding='utf-8')
                templ=[]
                known_placeholders = set()
                placeholders = []
                fields = []
                for line in f:
                        templ.append(line)
                        # Find placeholders
                        for placeholder_match in re.finditer(u"«(.+?)»", line):
                                placeholder = placeholder_match.group(1)
                                if placeholder not in known_placeholders:
                                        known_placeholders.add(placeholder)
                                        placeholders.append(placeholder)
                                        fields.append({'type': 'text', 'title': placeholder, 'key': placeholder})
                if len(placeholders) == 0:
                        print("No template placeholders were found")
                else:
                        print(placeholders)
                        replacement=[]
                        for item in placeholders:
                                question = "What should I use for «"+item+"» ?   "
                                value=input("\n" + question.rjust(50))
                                replacement.append(value)
                        print("\n")
                
                        counter = 0
                        for item in placeholders:
                                replace=replacement[counter]
                                item = "«" + item + "»"
                                templ = [t.replace(item,replace) for t in templ]
                                counter+=1

                final_out=""
                for item in templ:
                        final_out+=item
                print("Copy the following and paste it into Omnifocus")
                print("--------NOT THIS LINE-------------------------------------"+"\n")
                print(final_out)
                print("\n"+"--------NOT THIS LINE-------------------------------------")
                
        
finally:
        chdir(old_dir)

To run quickly, I have a ‘scripts’ directory. In there I made a file called ‘omni’.

On the terminal prompt, I changed the permissions of omni to 755

Omni has these contents:

#!/bin/ksh

cd ~/Dropbox/'Python script folder'

python3 omni.py

It would be great to be able to update a task - perhaps using the omnifocus:// task URL.

I could see Workflow externalising this quite nicely, assuming it could search in Omnifocus and produce a list of such URLs.

But even if it can’t, it’d still be good to have update.

Hi all,

I really appreciate the TaskPaper and automation support. I’d like to share my workflow and how I use this to help manage my photo shoots.

Using a small workflow in Editorial, I start with a master template that looks like this:

«title» @due(«due»):
Preflight @due(«due» -1d) @context(Photography):
- Charge batteries
- Clean lenses
	- 14mm @night @landscape
	- 24mm @night @landscape
	- 24-105mm
[....]

Packing Checklist @due(«due») @context(Packing) @parallel(True):
- Lenses @parallel(True)
	- 14mm @night @landscape
	- 24mm @night @landscape
	- 24-105mm
	- 50mm
	- 135mm @portrait
- Memory cards

CGP Grey @due(«due») @autodone(True) @context(Photography):
- Shoot  «title»

Post processing @due(«due» +1w) @context(Mac):
- «title» pictures  into Lightroom
- «title» post-processing
- «title» upload picks to 500px

Using my workflow, Editorial searches for unique tags and allows you to filter them before sending to OmniFocus. This means I have a single document with everything I might need, but the final project only includes relevant tasks. It’s a great way to quickly setup a new project that includes everything I need, but no more.

Hope you find it useful.

2 Likes

Regarding the /search parameter, is there any way to specify searching “Everything” instead of “Here” or “Remaining” by default?

Does anyone have a workflow (for workflow) that will take taskpaper input but will only take the first instance (unique) of <> ?
While I took some time to implement this in workflow I would like to see if I can just use a template to pass to workflow.

Thanks for your help

I have been away from this project for a while, is these still not a way to add tasks to existing Project/Folder structures??

I tried the following example from these forums:

Folder A:
Proj 1:
- task 4
- task 5
- task 6
Proj 2:
Proj 3
Folder B:
Sub Folder:
Deeper Project:
- task
- sub task I
- sub task II
- sub task III
- task
- task
Folder C:

When run in succession this will not add additional tasks into the folders, it just creates new folders/projects.

You can paste tasks into an existing Folder or Project, but you have to do so by specifying the Folder or Project as part of the Paste URL (as part of the TARGET parameter). As a result, you can only paste to one folder or project at a time using the Paste URL.

I created a Drafts action that finds the @project() or @folder() tag anywhere in your Draft, and creats the URL for you. You can find that action here:

http://drafts4-actions.agiletortoise.com/a/1xa

You could mimic this behavior in Workflow or Editorial or whatever other tool you want to use.

It would be possible to paste into multiple projects or folders if you set up Drafts or Editorial or Workflow to break down your text into separate bits and to generate multiple URLs to open as a result. But that’s more work than I’ve put into this for now.

Is there a way to use a template in workflow to populate a new project, but specifying how many of a particular task is required. I’m looking to setup a template for a new client commission that will require a number of materials, each of which I will need to source individually. I therefore want to be able to specify how many different materials are required, what each of them are, and have that automatically create the appropriate number of tasks, each populated with the correct material. Thanks

Absolutely. You should be able to use an “ask for input” function, I’d then input the materials with line breaks, split text, repeat with each (to add context, defer, etc as required), and then combine them afterwards and add them into the project. This way you can skip asking for how many (you can get the count if you like too).

Let me know if you’d like a demo Workflow :)

2 Likes

Rose you’re a star. Actually I would love a demo workflow if you have the time as I’m completely new to the whole Omnifocus / Workflow /scripting world.

The kind of thing I’m thinking of is a template where it asks me for a client’s name and furniture type and then asks the number of hardware requirements, then timber requirements followed by what they are and using those number inputs creates a number of associated tasks each populated with the relevant items. Not sure that makes sense…

3 Likes

Ok, here you are: OmniFocus Demo Workflow. When it asks for hardware or timber or “anything else” it expects a list of objects separated by line breaks. You don’t need to include the formatting for each item (unless you want to include context or defer or due), as the indentation and task identifier are added automatically.

I’ve not stuck to exactly what you asked for to try and give you a better overview of how this can work. And I include the combine text action each time as sometimes doing it magically goes a little wonky when adding to OF I’ve found.

2 Likes

Rose that is brilliant. Really appreciate your help. Not sure how far down this rabbit hole you want to go but if you are inclined to go any further this is a better explanation of where I’m trying to end up.

I have included a link to a flow diagram pdf and an example omnifocus pdf template on the following shared dropbox folder link. If its something thats quick for you to take a look at that would be great. Please don’t worry if its becoming a hassle.

Thanks again

For @cpac and @slcc2c (and anyone who is still tracking this large thread) - I created some scripts that would help with this. The scripts were intended to help streamline multi-project “brain dumps” from Windows into OmniFocus through the Editorial and Workflow apps. But if you wanted to use the method without Windows and just stick to entering all the tasks in Editorial manually, you could do that too.

Link to the method and discussion on this thread here: Taskpaper Sync to OmniFocus from Windows OS