Applescript – Merlin to Evernote

AppleScriptMerlin integrates easily with lots of other Mac and Windows applications. You can import, export, sync but also use applescript to connect between applications.

We’ve posted an Evernote > Merlin applescript in the past. It allows you to select notes in Evernote and import them to Merlin as file attachments to be able to view them offline and have them as part of your Merlin project.

This script is for those of you who want to transfer activities from Merlin to Evernote and create notes from an existing Merlin project. It goes throughout all activities of the top most opened project, checks if they already been synced to Evernote, if not it creates a note in related Evernote notebook, and writes there the content of the notes, names the note as the Merlin task, set expected end date of the task as creation date for the note (so one can check for it) and writes into Merlin project in the ‘additional title’ column the id of the note in Evernote in order for the script to be able to identify duplicates by re-transfers.

We don’t see how we can overwrite existing note content by applescript, so we tell the script to report existing notes and not to change them.

Feel free to download this Merlin to Evernote applescript and modify the sample as you find fitting your workflow needs at best.

(*
	This script goes throught all activities of the top most opened project, checks if they already been synced to Evernote, if not it creates a note in related Evernote notebook, and writes there the content of the notes, names the note as the Merlin task, set expected end date of the task as creation date for the note (and also as subject's date). 
	Written by Vicky Stamatopoulou
	For ProjectWizards
	Jun 3, 2013
*)

property NeedFeedBackForExistingNotes : "Would you like to get feedback for already existing notes?"
property NeedAProjectMessage : "You must have opened a project in Merlin in order to run this script."
property Done : "Merlin tasks were transferred into the notebook '"
property DoneSingular : "Merlin task was transferred into the notebook '"
property upsNoteFound : "Ups, note already exists in Evernote. 

Merlin cannot overwrite the note text. It will not change task "
global inList

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

		repeat with act in activities of parentActivity
			if (class of act is activity) then
				collectAllSubactivities(act, inList) of me
			end if
		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
	set inform to false
	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

	set feedback to display dialog NeedFeedBackForExistingNotes buttons {"Yes", "No"} default button "No"
	if button returned of feedback = "Yes" then set inform to true

	tell application "Evernote"
		set noteBookTitle to name of proj
		try
			notebook noteBookTitle
		on error
			create notebook noteBookTitle
		end try
	end tell
	set counter to 0

	repeat with act in allActivities
		set checkitem to false
		set noteName to ""
		set noteContent to ""
		set noteLocalID to ""
		set noteReminderDate to ""
		set noteContent to ""

		set actContent to activities of act
		try
			(item 1 of actContent)
			if class of (item 1 of actContent) is assignment then set checkitem to true
		on error
			set checkitem to true
		end try

		if checkitem then
			tell act

				set noteName to name

				if description is not missing value then set noteContent to description

				if subtitle2 is not missing value then set noteLocalID to subtitle2

				set noteReminderDate to (expected end date) as date
				tell application "Evernote"

					if noteLocalID is not "" then

						try
							set noteRef to note id noteLocalID of notebook noteBookTitle
							if inform then set dialogResult to display dialog upsNoteFound & "'" & noteName & "'" & " in notebook '" & noteBookTitle & "'." buttons {"OK"}

						on error
							set noteRef to create note with text noteContent title noteName notebook noteBookTitle created noteReminderDate
							set subject date of noteRef to noteReminderDate

							set noteLocalID to local id of noteRef
							tell application "Merlin" to set subtitle2 of act to (noteLocalID) as string
							set counter to counter + 1

						end try
					else
						set noteRef to create note with text noteContent title noteName notebook noteBookTitle created noteReminderDate
						set subject date of noteRef to noteReminderDate

						set noteLocalID to local id of noteRef
						tell application "Merlin" to set subtitle2 of act to (noteLocalID) as string
						tell application "Merlin" to set subtitle of act to (noteReminderDate) as string
						set counter to counter + 1
					end if

				end tell

			end tell
		end if
	end repeat
	tell application "Evernote" to synchronize

	activate
	set forDialogue to Done
	if counter = 0 then set counter to "No"
	if counter = 1 then set forDialogue to DoneSingular
	display dialog (counter & " " & forDialogue & noteBookTitle & "'.") as string buttons {"OK"}
end tell

Download: Merlin > Evernote