Omnifocus To Merlin Script WORKS - Use it here! AMAZING!

A hugely helpful friend of mine has managed to add the fix to Rob Trew’s script. It works! And now you can export from Omnifocus to Merlin. Install it into your scripts. Open Merlin then hop back to Omnifocus. Select the project you want to export, hit the script and BINGO! It will appear in Merlin.
Change that was needed from RobTrew’s as follows:
Replaced:

set blnContext to ((selected view mode identifier) of oWin is not
equal to pPROJECT)

With:

set blnContext to ((selected sidebar tab) of oWin is not equal to
pPROJECT)

And now it works. All the very best. This is fab. Scroll down to find Rob Trew’s updated script below:

-- Illustrative draft Ver 0.0

-- Copies anything selected in Omnifocus (Project or Context View) into MERLIN 2
-- Note that the whole sub-tree is copied, so only 'parent' elements need to be selected.
-- The destination is a new Merlin 2 document.

property pPROJECT : "project"
property pTASK : "task"
property pITEM : "item"

on run
	set {lstActivities, blnContext} to SelectedInOF()
	
	PlaceinMerlin(lstActivities)
end run

-- TRANSFERRING TO MERLIN

on PlaceinMerlin(lstTasks)
	if (length of lstTasks > 0) then
		tell application id "net.projectwizards.Merlin2"
			
			set oDoc to make new document
			set oRoot to root project of oDoc
			set title of oRoot to "OmniFocus import" & " " & (current date) as string
			
			my PlaceTasks(lstTasks, oRoot)
		end tell
	end if
end PlaceinMerlin

on PlaceTasks(lstTasks, oParent)
	using terms from application "Merlin"
		tell oParent
			repeat with oTask in lstTasks
				set {strName, blnDone, lstSubTasks, strNote, strParent, dteStart, dteDue, dteDone, lngMins, blnFlagged} to oTask
				
				set oMlnTask to make new activity at end of activities of oParent
				tell oMlnTask
					set title to strName
					if length of strNote > 0 then set description to strNote
					
					-- Assign any other properties here, e.g. ...
					------ if dteStart is not missing value then set given planned start date min to dteStart
					------ if dteDue is not missing value then set given planned end date max to dteDue
				end tell
				
				if length of lstSubTasks > 0 then
					my PlaceTasks(lstSubTasks, oMlnTask)
				end if
			end repeat
		end tell
	end using terms from
end PlaceTasks


-- READ SELECTED OmniFocus CONTENT TREE(S) TO NESTED APPLESCRIPT LISTS - Ver.02

on SelectedInOF()
	tell application "OmniFocus"
		set oWin to front window
		set blnContext to ((selected sidebar tab) of oWin is not equal to pPROJECT)
		tell content of oWin
			set lstContentSeln to selected trees
			if (count of lstContentSeln) > 0 then -- Whatever is SELECTED in content panel
				set lstTrees to lstContentSeln
				set blnAll to false
			else -- EVERYTHING in the content panel
				set lstTrees to trees
				set blnAll to true
			end if
		end tell
		{my Trees2List(oWin, lstTrees, blnContext, blnAll), blnContext}
	end tell
end SelectedInOF

on Trees2List(oWin, lstTrees, blnContext, blnAll)
	set lstTasks to {}
	
	using terms from application "OmniFocus"
		repeat with oNode in lstTrees
			set oValue to value of oNode
			set cClass to class of oValue
			
			if cClass is not item then
				if cClass is project then
					set end of lstTasks to my ListProject(oNode, oValue, blnContext, blnAll)
				else
					set end of lstTasks to my ListContext(oNode, oValue, blnAll)
				end if
			else
				set end of lstTasks to my ListUnProcessed(oNode, oValue, blnContext, blnAll)
			end if
		end repeat
	end using terms from
	lstTasks
end Trees2List

on ListProject(oNode, oValue, blnContext, blnAll)
	using terms from application "OmniFocus"
		tell oNode
			set lstChildren to trees of oNode
			tell oValue
				if (count of lstChildren) > 0 then
					{name, completed, my ListSubTrees(lstChildren, blnContext, blnAll), note, "", defer date, due date, completion date, estimated minutes, flagged}
				else
					{name, completed, {}, note, "", defer date, due date, completion date, estimated minutes, flagged}
				end if
			end tell
		end tell
	end using terms from
end ListProject

on ListContext(oNode, oValue, blnAll)
	using terms from application "OmniFocus"
		tell oNode
			set lstChildren to trees
			set oValue to value of oNode
			tell oValue
				if (count of lstChildren) > 0 then
					{name, false, my ListSubTrees(lstChildren, true, blnAll), note, "", missing value, missing value, missing value, 0, false}
				else
					{name, false, {}, note, "", missing value, missing value, missing value, 0, false}
				end if
			end tell
		end tell
	end using terms from
end ListContext


on ListUnProcessed(oNode, oValue, blnContext, blnAll)
	using terms from application "OmniFocus"
		tell oNode
			set lstChildren to trees
			
			if blnContext then
				set strName to "No Context"
			else
				set strName to "Inbox"
			end if
			
			tell oValue
				if (count of lstChildren) > 0 then
					{strName, false, my ListSubTrees(lstChildren, blnContext, blnAll), "", "", missing value, missing value, missing value, 0, false}
				else
					{strName, false, {}, "", "", missing value, missing value, missing value, 0, false}
				end if
			end tell
		end tell
	end using terms from
end ListUnProcessed

on ListSubTrees(lstTrees, blnContext, blnAll)
	set lstTasks to {}
	repeat with oNode in lstTrees
		set end of lstTasks to my ListTask(oNode, blnContext, blnAll)
	end repeat
	return lstTasks
end ListSubTrees

on ListTask(oNode, blnContext, blnAll)
	using terms from application "OmniFocus"
		tell oNode
			set oTask to value of oNode
			set lstSubTrees to trees of oNode
			
		end tell
		if blnContext then
			set oParent to containing project of oTask
		else
			set oParent to context of oTask
		end if
		if oParent is not missing value then
			set strParent to name of oParent
		else
			set strParent to ""
		end if
		tell oTask
			if (count of lstSubTrees) > 0 then
				{name, completed, my ListSubTrees(lstSubTrees, blnContext, blnAll), note, strParent, defer date, due date, completion date, estimated minutes, flagged}
			else
				{name, completed, {}, note, strParent, defer date, due date, completion date, estimated minutes, flagged}
			end if
		end tell
	end using terms from
end ListTask
3 Likes

Can your hugely helpful friend maybe fix Rob Trew’s WhereInOF script so that it works in OF2?

I would be mighty appreciative if he could!

Hi there! Unfortunately he’s rammed with work and made me promise not to send more at him. I’m so sorry!

Too bad. Thanks for answering, though.

I know this is an old thread, but I’m a newbie to scripts. How do I install the script (which I downloaded from Merlin more recently) ? I placed it in OF2’s Script Folder (and I opened AppleScript tool and opened to the OF app, but don’t really understand what to do there, as these instructions were in OF2’s help on Scripts).

This too doesn’t make sense to me : “You can add scripts that live in your OmniFocus toolbar by placing them in the directory accessible from the Help ▸ Open Scripts Folder menu item.”

Thanks for any help!

Use the Help > Open Scripts Folder command to open the scripts folder then drag in the script you want to install.

Once the script is in that folder you can add that script to your OmniFocus Toolbar using the View > Customise Toolbar… command or by right clicking on the toolbar itself. From within the menu that will appear, you can drag your script to the OmniFocus toolbar.

Click Done and then whenever you want to use the script, just click its icon on the toolbar.

2 Likes

Thanks! I found the answer by a video mentioned in an old article, but your reply nails it too! Much appreciated!

Example : https://learnomnifocus.com/tutorials/applescript-complete-await-reply-pro/

1 Like