bin/githubomnifocus.rb
def add_task(omnifocus_document, new_task_properties)
	# If there is a passed in OF project name, get the actual project object
	if new_task_properties['project']
		proj_name = new_task_properties["project"]
		proj = omnifocus_document.flattened_tasks[proj_name]
	end

	# Check to see if there's already an OF Task with that name in the referenced Project
	# If there is, just stop.
	name   = new_task_properties["name"]
	#exists = proj.tasks.get.find { |t| t.name.get.force_encoding("UTF-8") == name }
	# You can un-comment the line below and comment the line above if you want to search your entire OF document, instead of a specific project.
	exists = omnifocus_document.flattened_tasks.get.find { |t| t.name.get.force_encoding("UTF-8") == name }
	return false if exists

	# If there is a passed in OF tag name, get the actual tag object
	if new_task_properties['tag']
		tag_name = new_task_properties["tag"]
		tag = omnifocus_document.flattened_tags[tag_name]
	end

	# Do some task property filtering.  I don't know what this is for, but found it in several other scripts that didn't work...
	tprops = new_task_properties.inject({}) do |h, (k, v)|
		h[:"#{k}"] = v
		h
	end

	# Remove the project property from the new Task properties, as it won't be used like that.
	tprops.delete(:project)
	# Update the primary tag property to be the actual tag object not the tag name
  tprops.delete(:tag)
	tprops[:primary_tag] = tag if new_task_properties['tag']

	# You can uncomment this line and comment the one below if you want the tasks to end up in your Inbox instead of a specific Project
	#  new_task = omnifocus_document.make(:new => :inbox_task, :with_properties => tprops)

	# Make a new Task in the Project
	proj.make(:new => :task, :with_properties => tprops)

	puts "Created task " + tprops[:name]
	return true
end
# This method adds a new Task to OmniFocus based on the new_task_properties passed in
This method adds a new Task to OmniFocus based on the new_task_properties passed in
This method adds a new Task to OmniFocus based on the new_task_properties passed in
def add_task(omnifocus_document, new_task_properties)
	if new_task_properties['project']
		proj_name = new_task_properties["project"]
		proj = omnifocus_document.flattened_tasks[proj_name]
	end
	name   = new_task_properties["name"]
	exists = omnifocus_document.flattened_tasks.get.find { |t| t.name.get.force_encoding("UTF-8") == name }
	return false if exists
	if new_task_properties['tag']
		tag_name = new_task_properties["tag"]
		tag = omnifocus_document.flattened_tags[tag_name]
	end
	tprops = new_task_properties.inject({}) do |h, (k, v)|
		h[:"#{k}"] = v
		h
	end
	tprops.delete(:project)
  tprops.delete(:tag)
	tprops[:primary_tag] = tag if new_task_properties['tag']
	proj.make(:new => :task, :with_properties => tprops)
	puts "Created task " + tprops[:name]
	return true
end
def add_task ( omnifocus_document , new_task_properties ) if new_task_properties [ 'project' ] proj_name = new_task_properties [ "project" ] proj = omnifocus_document . flattened_tasks [ proj_name ] end name = new_task_properties [ "name" ] exists = omnifocus_document . flattened_tasks . get . find { | t | t . name . get . force_encoding ( "UTF-8" ) == name } return false if exists if new_task_properties [ 'tag' ] tag_name = new_task_properties [ "tag" ] tag = omnifocus_document . flattened_tags [ tag_name ] end tprops = new_task_properties . inject ( { } ) do | h , ( k , v ) | h [ :" #{ k } " ] = v h end tprops . delete ( :project ) tprops . delete ( :tag ) tprops [ :primary_tag ] = tag if new_task_properties [ 'tag' ] proj . make ( :new => :task , :with_properties => tprops ) puts "Created task " + tprops [ :name ] return true end
This method adds a new Task to OmniFocus based on the new_task_properties passed in
This method adds a new Task to OmniFocus based on the new_task_properties passed in
# If there is a passed in OF project name, get the actual project object # Check to see if there's already an OF Task with that name in the referenced Project # If there is, just stop. #exists = proj.tasks.get.find { |t| t.name.get.force_encoding("UTF-8") == name } # You can un-comment the line below and comment the line above if you want to search your entire OF document, instead of a specific project. # If there is a passed in OF tag name, get the actual tag object # Do some task property filtering.  I don't know what this is for, but found it in several other scripts that didn't work... # Remove the project property from the new Task properties, as it won't be used like that. # Update the primary tag property to be the actual tag object not the tag name # You can uncomment this line and comment the one below if you want the tasks to end up in your Inbox instead of a specific Project #  new_task = omnifocus_document.make(:new => :inbox_task, :with_properties => tprops) # Make a new Task in the Project
omnifocus_document
new_task_properties