Applescript – MS Word to Merlin

Can I import a selected list of activities from a MS Word document into Merlin as tasks?

Merlin can import various file formats.  For a complete list please check related topic in Merlin online help.

MS Word documents are most commonly used for long texts and maybe project or task scope description. Lists are usually recorded in MS Excel, GTD applications, or even mindmapping software. To import tasks out of an MS Word document, you should export it into a compatible format.

  • So you select in MS Word File > Save as… > Plain Text
  • MS Word prompts for the desired formatting and encoding
  • You save the file
  • You drag the plain text file to Merlin’s project listing and
  • map the field in the plain text to Merlin’s <title> column.
  • Merlin will then import the list into the existing project.

To quicken things however, we have created a small Applescript sample, which handles the current MS Word selection, goes through its paragraphs and enters them as tasks into an existing Merlin project.

If interested, feel free to download, use or modify as you like. 

(* 	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 through selected text paragraphs of MS Word documents, 
	and inserts them as tasks in existing Merlin projects.  

        To use it, just select the paragraphs you want to transfer to Merlin and start this script.  

	Version info: 1.0
	Author: Vicky Stamatopoulou
	Date: September 2012

*)
----

property ErrorMessage1 : "You must have an open project in order to run this script."
property GoodNews1 : "Good news. "
property GoodNews2 : " items had been imported to the current Merlin project from MS Word."
property BadLuck1 : "An error occured."
property BadLuck2 : "No items had been imported. Please try exporting your MS Word document in plain text instead."

on SearchReplace(sourceStr, searchString, replaceString)
	-- replace  with  in  
	set searchStr to (searchString as text)
	set replaceStr to (replaceString as text)
	set sourceStr to (sourceStr as text)
	set saveDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to (searchString)
	set theList to (every text item of sourceStr)
	set AppleScript's text item delimiters to (replaceString)
	set theString to theList as string
	set AppleScript's text item delimiters to saveDelims
	return theString
end SearchReplace

tell application "Microsoft Word"
	activate
	-- get content of active document
	-- and do a list of contained paragraphs
	
	-- if you want to import the complete project UNCOMMENT following 2 lines
	--tell active document
	--set mytext to content of text object
	
	-- if want to import the complete project COMMENT following 2 lines
	tell selection
		try
			set mytext to content of text object
			
			set mytext to paragraphs of mytext
			set goForIt to true
		on error
			display dialog "Nothing selected in MS Word, so there is nothing to be transferred to Merlin." buttons {"Ok"}
			set goForIt to false
		end try
	end tell
end tell
if goForIt then
	tell application "Merlin"
		
		try
			set doc to the first document
		on error
			activate
			display dialog ErrorMessage1
			set chosenFile to (choose file)
			open chosenFile
			set doc to the first document
		end try
		
		set proj to root project of doc
		set k to 0
		repeat with theItem in mytext
			set theItem to SearchReplace(theItem, return, "") of me
			
			if theItem is not "" then
				set k to k + 1
				set TheNewOne to (make new activity) as specifier
				set title of TheNewOne to theItem
				move TheNewOne to the end of every activity of proj
			end if
		end repeat
		activate
		if k > 0 then
			display dialog GoodNews1 & return & k & GoodNews2 buttons {"Ok"}
		else
			display dialog BadLuck1 & return & BadLuck2 buttons {"Ok"}
		end if
	end tell
end if

Download: GetMSWordLines.scpt.zip