View Single Post
Quote:
Originally Posted by imlad View Post
This works very well. The only caveat is that the Evernote Note containing the task needs to by synchronized BEFORE the task section is highlighted. Otherwise there is a prompt asking to synchronized before making a notes link, and the OF task does not get the link generated. I tried to force synchronization in the script, but I think a delay needs to be put in before the copying of the Note link, and I have not figured out how to do it. If a note is synched all is well.
I tweaked the code to pull from Evernote to look like this:

Code:
tell application "Evernote"
	set noteList to selection
	set currentEvernote to item 1 of noteList
	set theTitle to title of currentEvernote
	set theTaskNote to note link of currentEvernote
	if (theTaskNote is missing value) then
		synchronize
		repeat 6 times
			delay 0.25
			set theTaskNote to note link of currentEvernote
		       	if (theTaskNote is not missing value) then
				exit repeat
			end if
		end repeat
		if (theTaskNote is missing value) then
			display dialog "Sync was needed and is taking a while; dismiss me when sync is complete"
			set theTaskNote to note link of currentEvernote
		end if
	end if
	if (source URL of currentEvernote is not missing value) then
		set theTaskNote to source URL of currentEvernote & (return) & (return) & theTaskNote
	end if
end tell
This initiates a sync if the note link doesn't exist yet, checks for 1.5 seconds to see if the link was created, and then prompts with a dialog if the sync is still not finished. Seems to work pretty well. I couldn't find any way to detect if the EN sync finished, and it's not a good idea to loop forever, hence the dialog as a failsafe.

(I also changed the code to not use system events to copy the note and link. For my purposes, I don't need to copy the selected text to OF.)

/Nick