The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Today's Posts

 
Send from OmniPlan to OmniFocus Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Here is an illustrative first draft, which transfers any activities selected in OmniPlan (with their sub-activities) to a new date-stamped folder in OF.

--

Code:
-- ver 0.2 (Exports to an OF Folder, rather than making all tasks children of the same project)

-- All activities selected in OmniPlan GUI transferred (with their descendants) to 
-- a new date-stamped *folder* in OmniFocus, and each parent element selected in OP becomes a project in the OF folder,
-- with the descendent OP sub-tasks exported as a hierarchy of OF tasks
--
-- An alternative line shown in the FillofProj() function would exclude transfer of estimated minutes

property pstrOFProjectName : "OmniPlan import"

on run
	set lstTasks to OPSelected()
	
	if length of lstTasks > 0 then
		PlaceInOF(lstTasks)
	else
		display dialog "Select parent task(s) in OmniPlan, and try again"
	end if
end run

-- Get a nested list of the selected OmniPlan activities
on OPSelected()
	tell application "OmniPlan"
		tell front window
			set lstOPTasks to selected tasks
			if (count of lstOPTasks) > 0 then
				return my Tasks2NameList(lstOPTasks)
			else
				return {}
			end if
		end tell
	end tell
end OPSelected

-- -- Translate OmniPlan activities to a nested list of activity names
on Tasks2NameList(lstOPTasks)
	using terms from application "OmniPlan"
		set lstTasks to {}
		repeat with oTask in lstOPTasks
			tell oTask
				set lstChiln to child tasks
				if (lstChiln is not missing value) and (length of lstChiln) > 0 then
					set end of lstTasks to {name, my Tasks2NameList(lstChiln), starting date, ending date, note, duration / 60}
				else
					set end of lstTasks to {name, {}, starting date, ending date, note, duration / 60}
				end if
			end tell
		end repeat
		return lstTasks
	end using terms from
end Tasks2NameList

-- Place nested list of activity names in a new OF project
on PlaceInOF(lstActivities)
	if length of lstActivities > 0 then
		tell application "OmniFocus"
			tell front document
				set oFolder to make new folder with properties {name:pstrOFProjectName & " " & my SysDate()}
				my FillOFFolder(oFolder, lstActivities)
			end tell
		end tell
	end if
end PlaceInOF

on SysDate()
	current date
end SysDate

-- Transfer activities to the specified project (or parent task)
on FillOFFolder(oFolder, lstActivities)
	using terms from application "OmniFocus"
		tell oFolder
			repeat with oAct in lstActivities
				set {strName, lstChiln, dteStart, dteDue, strNote, lngMins} to oAct
				if strNote is missing value then
					set oProj to make new project with properties {name:strName, start date:dteStart, due date:dteDue, estimated minutes:lngMins}
					-- set oProj to make new project with properties {name:strName, start date:dteStart, due date:dteDue}
				else
					set oProj to make new project with properties {name:strName, start date:dteStart, due date:dteDue, note:strNote, estimated minutes:lngMins}
					-- set oProj to make new project with properties {name:strName, start date:dteStart, due date:dteDue, note:strNote}
				end if
				if length of lstChiln > 0 then
					my FillOFProj(oProj, lstChiln)
				end if
			end repeat
		end tell
	end using terms from
end FillOFFolder


-- Transfer activities to the specified project (or parent task)
on FillOFProj(oProj, lstActivities)
	using terms from application "OmniFocus"
		tell oProj
			repeat with oAct in lstActivities
				set {strName, lstChiln, dteStart, dteDue, strNote, lngMins} to oAct
				if strNote is missing value then
					-- set oTask to make new task with properties {name:strName, start date:dteStart, due date:dteDue, estimated minutes:lngMins}
					set oTask to make new task with properties {name:strName, start date:dteStart, due date:dteDue}
				else
					-- set oTask to make new task with properties {name:strName, start date:dteStart, due date:dteDue, note:strNote, estimated minutes:lngMins}
					set oTask to make new task with properties {name:strName, start date:dteStart, due date:dteDue, note:strNote}
				end if
				if length of lstChiln > 0 then
					my FillOFProj(oTask, lstChiln)
				end if
			end repeat
		end tell
	end using terms from
end FillOFProj

Last edited by RobTrew; 2011-09-10 at 12:10 AM.. Reason: Workaround for a new bug in the Applescript library
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with send-to-omnifocus hh15302 OmniFocus for iPad 1 2011-12-10 07:49 AM
Send to Omnifocus mcortina OmniFocus Extras 0 2011-07-11 10:04 AM
New to Omnifocus: How to send an email from omnifocus iain.c.devine Applying OmniFocus 2 2011-01-31 10:30 PM
Send to Omnifocus? bcalloway OmniFocus for iPhone 2 2010-01-23 07:24 PM
Send Firefox URL to Omnifocus spnyc OmniFocus Extras 14 2009-02-12 12:44 PM


All times are GMT -8. The time now is 09:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.