Create Reminders for Available OmniFocus Tags

I would like a Shortcut which would create reminders in my “Action” list of Apple Reminders linking back to OmniFocus tags having at least one available action associated with it.

Requirements

  • Reminder has the same name as the OmniFocus tag
  • Reminder has a URL to the OmniFocus tag
  • If an incomplete reminder already exists with that name, a new reminder is not created

I almost have this working. The shortcut starts with the “Run Javascript for Automation” action. This javascript successfully creates reminder records with the links:

function run(input, parameters) {
    var of  = Application('OmniFocus');
    var doc = of.defaultDocument();
    var tags = doc.tags();

    var result = tags.map(function(tag) {
        var id = tag.id();
        // Construct a deep-link URL for this tag
        var urlString = 'omnifocus:///tag/' + encodeURIComponent(id);
        return {
            name: tag.name(),
            url:  urlString
        };
    });

    return JSON.stringify(result);
}

Unfortunately I can not find a way to filter out tags not having an available action. Numerous approaches have resulted in javascript syntax errors. I’m using ChatGPT to help me and it has the OmniAutomation reference but still can’t seem to find a way to resolve…

I got it! Just posting in case anyone is curious

function run(input, parameters) {
    var of  = Application('OmniFocus');
    var doc = of.defaultDocument();
    
    // Only include tags that have one or more available tasks
    // and whose names begin with "@"
    var tags = doc.tags().filter(function(tag) {
        return tag.availableTasks.length > 0
            && tag.name().startsWith('@');
    });
    
    var result = tags.map(function(tag) {
        var id = tag.id();
        // Construct a deep-link URL for this tag
        var urlString = 'omnifocus:///tag/' + encodeURIComponent(id);
        return {
            name: tag.name(),
            url:  urlString
        };
    });
    
    return JSON.stringify(result);
}```
1 Like