Applescript – Transfer selected activities to Reminders

To transfer the scheduling of your Merlin project as events in Calendar.app or reminders in the Reminder.app you have two options: you can export or publish to iCal.

Exporting and publishing to iCal work for users of OS X Lion and earlier with iCal. For users of OS X Mountain Lion and newer they transfer to Apple’s Calendar.app and Reminders.app

To be more specific Merlin exports or syncs the complete project, and/or the resource assignments whereby if you choose to

  • convert dates to All day events or those with times, the activities will be transferred as events in local calendars in the Calendar.app
  • convert dates as todos, the activities will be listed in the Reminders.app

We have had however some support requests wanting to know how to export/sync just a selection or a subset of activities. Our answer is, there is no explicit function in Merlin exporting the selection, but you may of course right click the specific project structures, call “Save selection” out of the contextual menu, open the newly created project and export to iCal as todos.

If you want to do this by script, please read further.
We have already posted an Applescript transferring selected structures to Calendar.app.  This script here, transferring selected activities to Reminders was inspired by a comment recorded on that post.

(* 	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 ©2014 ProjectWizards, Melle, Germany. All rights reserved.
*)

(*
	This script goes thought your current Merlin activities selection and transfers it to Reminders
	It checks for the existing Lists and offers the option to write into an existing list or to create a new one. 
	
	Merlin 			> Reminders
	----------------------------------
	title 				> name
	priority 			> priority
	notes 			> body
	planned start date > due date
	
	Author: 		Vicky Stamatopoulou	
	
*)
--
---------------------------
property pleaseMakeASelection : "Please select the activities you would like to handle."
property whichList : "Select a reminder list in which the activities should be inserted or create a new list!"
property overwriteOkButton : "Use selected"
property overwriteCancelButton : "Create New"


tell application "Merlin"
	activate
	set myselection to selected object of main window of document 1 as list
	
	if (count of myselection) is 0 then
		display dialog pleaseMakeASelection buttons {"Ok"} default button "Ok"
	else
		
		set doc to the first document
		set proj to root project of doc
		set TheMerlinProj to title of proj
		
		
		tell application "Reminders"
			
			-- collect all reminder lists to offer to the user
			set theLists to lists
			set theListNames to {}
			repeat with aList in lists
				set theListNames to theListNames & name of aList as list
			end repeat
			activate
			set aList to choose from list theListNames with prompt whichList OK button name "Use selected" cancel button name overwriteCancelButton without multiple selections allowed
			
			if aList is equal to false then
				-- a new reminder list is to be created
				set theList to every list whose name is TheMerlinProj
				if theList is {} then
					set theList to make new list with properties {name:TheMerlinProj}
					
				else
					set theList to make new list with properties {name:TheMerlinProj & " " & time string of (current date)}
				end if
			else
				-- an existing reminder list will be used
				set theList to every list whose name contains aList
			end if
			
		end tell
		set allActivities to myselection
		
		repeat with act in allActivities
			-- collect: title, priority, notes, planned start date, planned end date
			set TheTitle to title of act as text
			
			set ThePrio to priority of act
			set ThePrioNumber to 0
			-- map a Merlin priority to Reminder priority levels
			-- property PriorityList : {{value:0, name:"None"}, {value:9, name:"Low"}, {value:5, name:"Medium"}, {value:1, name:"High"}}
			
			if ThePrio is very high priority then set ThePrioNumber to 1
			if ThePrio is high priority then set ThePrioNumber to 1
			if ThePrio is normal priority then set ThePrioNumber to 0
			if ThePrio is very low priority then set ThePrioNumber to 9
			if ThePrio is low priority then set ThePrioNumber to 9
			
			
			set TheNotes to description of act
			if TheNotes is missing value then set TheNotes to ""
			if class of act is activity then
				try
					set TheStartDate to (planned start date of act) as date
				on error
					set TheStartDate to (expected start date of act) as date
				end try
				try
					
					set TheEndDate to (planned end date of act) as date
				on error
					set TheEndDate to (expected end date of act) as date
				end try
				
				
				-- create a reminder
				tell application "Reminders" to set myReminder to make new reminder in theList with properties {name:TheTitle, due date:TheStartDate, body:TheNotes, priority:ThePrioNumber}
				
				
			end if
		end repeat
		-- comment following row if you don't want the last inserted item to be opened
		tell application "Reminders" to show myReminder
	end if
end tell

2 thoughts on “Applescript – Transfer selected activities to Reminders

Comments are closed.