Applescript – elapsed duration in human friendly time units

When planing and managing your projects with Merlin for Mac OS X you have 4 main windows: Activities, Resources, Netplan, Utilization.

Depending on the view you have selected, the main area offers you different details and information about your project. You can view and in certain cases modify the main outline of your project, adding activities, groups and milestones. Furthermore, this area also allows you to work interactively with the Gantt chart, Netplan and resource utilization.

Per default the label in the Gantt bar show the expected duration in working times. So it may show 2 days for example for a task starting Friday and ending Monday if weekend is defined to be workfree time.

If you want the label in the Gantt to show the real time elapsed, you may do so. Just go to View > Show View Options > Styles
Click into the label you want to edit and select “expected elapsed duration” for its content.

This of course would then show the duration in e-units. What to do if you don’t want those edays, emonths, eweeks to be shown? You may use attached script sample created in AppleScript.

It goes throught all activities of the top most opened project, checks for the expected elapsed duration of the task, and writes it in the subtitle field in human friendly units. If you enable the display of “subtitle” for the label, you are set.

Note: The script cannot create a live connection between the columns “subtitle” and “expected elapsed duration”. That is, before printing your project, make sure you call the script again Gantt  to actualize outputted data.

(* 	Scripting with Merlin 2

	You may incorporate this ProjectWizards sample code into your program(s) without
	restriction.  This ProjectWizards sample code has been provided "AS IS" and the
	responsibility for its operation is yours.  You are not permitted to
	redistribute this ProjectWizards sample code as "ProjectWizards sample code" after having
	made changes.  If you're going to redistribute the code, we require
	that you make it clear that the code was descended from ProjectWizards sample
	code, but that you've made changes.

	Copyright ©2012 ProjectWizards, Melle, Germany. All rights reserved.
*)

(*
	This script goes throught all activities of the top most opened project, checks for the expected elapsed duration of the task, and writes in the subtitle field. It won't transfer the estimated flag.

	Written by Vicky Stamatopoulou
	For ProjectWizards
	Mai 29, 2012
*)
--

---------------------------

property NeedAProjectMessage : "You must an opened project in order to run this script in Merlin."
property Done : "Done. Expected elapsed duration was transferred to the subtitle column."

global inList, TheDueDate

on collectAllSubactivities(parentActivity)
	global inList
	tell application "Merlin"
		set inList to inList & (parentActivity as list)

		repeat with act in activities of parentActivity
			collectAllSubactivities(act, inList) of me
		end repeat

	end tell
end collectAllSubactivities

on allSubActivities(parentActivity)
	global TheDueDate
	set inList to {}
	tell application "Merlin"
		collectAllSubactivities(parentActivity, inList) of me
	end tell
	return inList
end allSubActivities

tell application "Merlin"
	global inList
	try
		set doc to the first document
	on error
		display dialog NeedAProjectMessage
		set chosenFile to (choose file)
		open chosenFile
		set doc to the first document
	end try

	set proj to root project of doc

	set allActivities to allSubActivities(proj) of me

	repeat with act in allActivities

		tell act
			set elapsedDuration to expected elapsed duration
			set theValueAlone to amount of elapsedDuration
			if theValueAlone > 0 then
				set theValueAlone to (round ((theValueAlone) * 100)) / 100
			else
				set theValueAlone to round theValueAlone
			end if
			set subtitle to (theValueAlone) & " " & (unit of elapsedDuration) as string
		end tell

	end repeat

	display dialog Done buttons {"OK"}
end tell