Tinderbox Forum

Sent tasks to a from TBX to OmniFocus Project

I saw this wonderful post from Will (@yggy): An Applescript that creates an Omnifocus project from a Tinderbox Note and reciprocally links them. Anyone have an idea on how I can modify it so that I can send Action Items/Tasks from Tinderbox to a specific project (/folder/projectname/) in OmniFocus. Lets assume, based on Will’s code that I know the URL of the project in question, so I think there would be a way to select the project and then add tasks to it. I just can’t figure put how. I forget to look up AppleScript Properties in Tinderbox and OmniFocus to start teasing out the best way to do this.

@wtreese helped me find some instructions, but struggling to make them work: https://github.com/jsit/omnifocus-3-applescript-guide.

I would love it if the code would only create a new project if the project name or ide in Omnifocus does not already exist, likewise a new tasks if that task does not already exists. Once I have that working I can see a path where another attribute values are exchanged backand forth, e.g. status, startdate, enddate, etc.

I’ve made a ton of progress.

This works to create a project:

tell application "Tinderbox 9"
	tell front document's selection
		set noteName to name
		set noteURL to value of (attribute named "NoteURL")
	end tell
end tell
tell front document of application "OmniFocus"
	set theProject to make new project with properties {name:noteName, note:noteURL}
	set omniFocusID to id of theProject
end tell
tell application "Tinderbox 9"
	tell front document's selection
		set value of (attribute named "Badge") to "link"
		set value of (attribute named "Color") to "poppy"
		set value of (attribute named "KeyAttributes") to "URL;"
		set value of (attribute named "OmniFocusID") to (omniFocusID)
	end tell
end tell

This works tp create tasks on an existing project.

tell application "Tinderbox 9"
	tell front document's selection
		set theTaskName to name
		set theTaskText to value of (attribute named "Text")
		set theProjectID to value of (attribute named "OmniFocusProdID")
		set noteURL to value of (attribute named "NoteURL")
		set theStatus to value of (attribute named "Status")
	end tell
end tell
tell front document of application "OmniFocus"
	set theProject to first flattened project where its id is theProjectID
	
	tell theProject
		set theTask to make new task with properties {name:theTaskName, note:theTaskText}
		set omniFocusTaskID to id of theTask
	end tell
end tell
tell application "Tinderbox 9"
	tell front document's selection
		set value of (attribute named "Badge") to "link"
		set value of (attribute named "Color") to "poppy"
		set value of (attribute named "URL") to ("omnifocus:///task/" & omniFocusTaskID)
		set value of (attribute named "OmniFocusTaskID") to (omniFocusTaskID)
		
	end tell
end tell

Now, what I can’t figure out is the following:

  1. how to pass a dueDae that Omnifocus will accept
  2. how to pass the status of the task or project to OmniFocus
  3. how to test if taskID already exists and if it does not not recreated it by rather pull updates from Omnifocus into Tinderbox
  4. Retrieve new tasks created in OmniFocus project and add them to the TBX
  5. pass tags from Tinderbox to OmniFoucs and visa versa
  6. how up pull updated changes, e.g. status, back to Tinderbox

I don’t have Omnifocus to test with, but some guesses:

  1. Would something like this work for the due date?
set myDueDate date "7/31/2022"
set theTask to make new task with properties {name:theTaskName, note:theTaskText, due date:MyDueDate}
  1. I think there’s a special way of formatting status codes, but I don’t know what it is.

  2. For getting new tasks: could you get them by storing the last-checked date in Tinderbox, and then fetching by later than last checked? Alternatively, if you have OmniFocus IDs in Tinderbox, you could iterate over the whole list, I suppose. Here’s post that has some code in the ballpark of looping over things, and there does seem to be a mod time.

  3. I’d guess there’s a function to get a task by ID?

  4. Don’t know about tags in OmniFocus. Some hints on the web that the scripting for them is less developed, but hard to be sure.

  5. For pulling changes: does OmniFocus have a modified-time for task record? If not, you might just have to loop over everything and check. Which is kind of a drag, but probably not terribly hard.

For
Also, there’s an Omnifocus forum with Applescript discussions at https://discourse.omnigroup.com/c/automation/omnifocus-automation/6

Thanks. I tried that approach for date and OmniFocus did not accept it. What I’d really like to do is pass the date from Tinderbox, i.e., not hard code it. Again, it is not clear to me what date format OmniFocus will accept. Tinderbox is passing Omnifocus “2022-07-11T09:03:22-07:00” which OmniFocus does not like. It is not clear to me how to reform the date to something OmniFocus likes.

I am capturing both the project ID and tasks ID when I create them in Omnifocus from Tinderbox. It is not clear to me yet how to pull a list of IDs from Omnifocus, compare them, and then update notes or create new ones that don’t yet exist.

if anyone is up for a Tinderbox/OmniFocus AppleScript Hacksession via Zoom, that would be awesome. I think this would be the most efficient way to knock a few of these items/ideas out.

@sumnerg, how are you? I was wonder, with your AppleScript prowess, if you could point me in the right direction with how to write conditional AppleScript, e.g. if theProject in omnifocus exists then do this.