Skip to content

Instantly share code, notes, and snippets.

@doug4j
Created January 1, 2019 17:16
Show Gist options
  • Select an option

  • Save doug4j/5fc27ddb926b19a71f939f0c855988d3 to your computer and use it in GitHub Desktop.

Select an option

Save doug4j/5fc27ddb926b19a71f939f0c855988d3 to your computer and use it in GitHub Desktop.

Revisions

  1. doug4j created this gist Jan 1, 2019.
    20 changes: 20 additions & 0 deletions of3-add-proj-if-it-does-not-exist.js.scrpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    var projName = "My First Auto-created Project";

    var app = Application("Omnifocus")
    app.includeStandardAdditions = true
    var doc = app.defaultDocument
    var matchingProjects = doc.flattenedProjects.whose({name: projName})
    var theProject = null
    if (matchingProjects.length == 0) {
    theProject = app.Project({
    name: projName,
    status: 'active'
    })
    doc.projects.push(theProject)
    app.displayDialog("Created new project")
    } else {
    theProject = matchingProjects[0]
    app.displayDialog("Reused existing project")
    }
    //theProject is now set (whether created new or reading from match)