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 Search Today's Posts Mark Forums Read

 
Send to Omnifocus from Merlin Thread Tools Search this Thread Display Modes
Hello all.
I'm not well into creating Applescripts and 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". Any help would be much appreciated.

Best regards,

Arild
 
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)
 
That's a great script, Rob - thanks very much.
 
really great sript RobTrew
 
Fantastic!
I saved your script under users/[username]/Library/Application Support/Merlin/SendToMenu and it works like a, well, charm.

Thanks a lot!
 
Quote:
Originally Posted by Arild View Post
I saved your script under users/[username]/Library/Application Support/Merlin/SendToMenu
That's a useful tip - thanks. I'm glad the script is useful.

Rob.
 
By the way, Rob (and Omnifocus): Would you mind if I uploaded the script to the google group for Merlin users? Should be people there really appreciating this script.

Regards,

Arild
 
Quote:
Originally Posted by Arild View Post
Would you mind if I uploaded the script to the google group for Merlin users?
Fine by me - it's just a simple sketch ...
 
I have slightly edited the code in the original post, above to ver 0.3

It now exports to a date-stamped OF folder (rather than a single project), and each top-level item in the Merlin selection becomes an OF project.

Last edited by RobTrew; 2010-03-02 at 01:09 PM.. Reason: Ver 0.3
 
Hi RobTrew,

we have tested your script and found it works wonderfully in Merlin. Please contact us (support at projectwizards dot net). We would like to discuss a possibility we have in mind.

Best regards from ProjectWizards, Vicky
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting to Merlin 2 FROM Omnifocus RobTrew OmniFocus Extras 2 2013-03-12 11:37 PM
Update Merlin 2 tasks using OmniFocus JamieStarr OmniFocus Extras 4 2011-12-14 12:41 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


All times are GMT -8. The time now is 03:01 PM.


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