View Single Post
Quote:
Originally Posted by Arild View Post
I wonder if any of you has created a script for exporting Merlin 2 activities to Omnifocus? Preferably to place under Merlin's "Send to".
Here is an illustrative first draft, which transfers any activities selected in Merlin (with their sub-activities) to a new date-stamped Folder in OF.

I am not aware of any way of adding this to the Send To menu, but if you save the script with a suitable name and place it in

/Users/[Your User Name]/Library/Scripts/Applications/Merlin

then it will appear in Merlin's script menu.

Code:
-- ver 0.5  Exports tasks selected in Merlin to OF Folder 
-- Commented alternative code would allow for export of some additional fields 
------(dates, duration, very high priority, completion etc)
-- Copyright ©2010 Robin Trew, UK. All rights reserved.


-- Note that all descendants of any selected nodes are exported.
-- (There is no need to select children if their parents or ancestors are already selected)

property pstrOFFolderName : "Merlin import"
property pMinsPerHour : 3600 as integer
property pNullString : "" as string

on run
	set lstActivities to MlnSelected()
	
	PlaceInOF(lstActivities)
end run

-- Get a nested list of the selected Merlin activities
on MlnSelected()
	tell application id "net.projectwizards.Merlin2"
		set oDoc to document of front window
		set oMerlnSeld to selected objects of main window of oDoc
		if length of oMerlnSeld > 0 then
			my Acts2NameList(oMerlnSeld, {})
		else
			{}
		end if
	end tell
end MlnSelected

-- Translate Merlin activities to a nested list of activity properties
-- {strName, blnDone, lstSubTasks, strNote, strParent, dteStart, dteDue, dteDone, lngMins, blnFlagged}

on Acts2NameList(lstSeln, lstParent)
	using terms from application "Merlin"
		repeat with oItem in lstSeln
			set lstChiln to {}
			set lstActs to activities of oItem
			if length of lstActs > 0 then
				set lstChiln to my Acts2NameList(lstActs, {})
			end if
			tell oItem
				-- 				set dblCompletion to given actual completion
				-- 				set blnDone to (dblCompletion is not missing value) and not (dblCompletion < 1)
				-- 				set blnFlagged to (priority is very high priority)
				-- 				
				-- 				set recDurn to planned duration
				-- 				tell recDurn
				-- 					set dblAmount to amount
				-- 					set eUnit to unit
				-- 				end tell
				-- 				if dblAmount > 0 then
				-- 					if eUnit = hours then
				-- 						set lngMins to dblAmount * pMinsPerHour
				-- 					else if eUnit = minutes then
				-- 						set lngMins to dblAmount
				-- 					else if eUnit = seconds then
				-- 						set lngMins to dblAmount / 60
				-- 					else
				-- 						set lngMins to 0
				-- 					end if
				-- 				end if				
				-- 				set end of lstParent to {name, blnDone, lstChiln, description, pNullString, planned start date, planned end date, actual end date, lngMins, blnFlagged}
				
				set end of lstParent to {name, false, lstChiln, description, pNullString, missing value, missing value, missing value, 0, false}
			end tell
		end repeat
	end using terms from
	return lstParent
end Acts2NameList

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

-- Transfer activities to the specified OF folder
on FillOFFolder(oFolder, lstActivities)
	using terms from application "OmniFocus"
		tell oFolder
			repeat with oAct in lstActivities
				set {strName, blnDone, lstChiln, strNote, strParent, dteStart, dteDue, dteDone, lngMins, blnFlagged} to oAct
				if (strNote is not missing value) and (length of strNote > 0) then
					
					set oProject to make new project with properties {name:strName, note:strNote}
				else
					set oProject to make new project with properties {name:strName}
				end if
				
				if length of lstChiln > 0 then
					my FillOFProj(oProject, 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, blnDone, lstChiln, strNote, strParent, dteStart, dteDue, dteDone, lngMins, blnFlagged} to oAct
				if (strNote is not missing value) and (length of strNote > 0) then
					set oTask to make new task with properties {name:strName, note:strNote}
				else
					set oTask to make new task with properties {name:strName}
				end if
				-- 				tell oTask
				-- 					if blnDone then set completed to true
				-- 					if not dteStart is missing value then set start date to dteStart
				-- 					if not dteDue is missing value then set due date to dteDue
				-- 					if not dteDone is missing value then set date completed to dteDone
				-- 					if lngMins > 0 then set estimated minutes to lngMins
				-- 					if blnFlagged then set flagged to blnFlagged
				-- 				end tell
				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; 2010-03-03 at 03:02 PM.. Reason: Ver 5 - Allows for exporting additional fields (dates etc)