The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Send to Omnifocus from Merlin (http://forums.omnigroup.com/showthread.php?t=15086)

Arild 2010-01-20 03:01 AM

Send to Omnifocus from Merlin
 
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

RobTrew 2010-01-22 04:00 AM

[QUOTE=Arild;72050]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". [/QUOTE]

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/[I][Your User Name[/I]]/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[/CODE]

Brian 2010-01-22 05:10 PM

That's a great script, Rob - thanks very much.

james68 2010-01-23 02:47 AM

really great sript RobTrew

Arild 2010-01-25 02:44 AM

Fantastic!
I saved your script under users/[username]/Library/Application Support/Merlin/SendToMenu and it works like a, well, charm.

Thanks a lot!

RobTrew 2010-01-25 04:59 AM

[QUOTE=Arild;72298]
I saved your script under users/[username]/Library/Application Support/Merlin/SendToMenu[/QUOTE]

That's a useful tip - thanks. I'm glad the script is useful.

Rob.

Arild 2010-02-23 06:50 AM

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

RobTrew 2010-02-23 07:57 AM

[QUOTE=Arild;73892]Would you mind if I uploaded the script to the google group for Merlin users? [/QUOTE]

Fine by me - it's just a simple sketch ...

RobTrew 2010-03-02 10:29 AM

I have slightly edited the code in the [URL="http://forums.omnigroup.com/showpost.php?p=72150&postcount=2"]original post, above[/URL] 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.

vicky 2010-03-03 04:24 AM

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


All times are GMT -8. The time now is 07:27 PM.

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