Applescript variable unknown to actions


in the clipboard of OS X I have following information:

When was Peter born?

The first line is the question, the second the answer.

In KM I use the following Applescript to split up this text to a variable that contains the question and another one that contains the answer:

	set clipboardText to (clipboard as text)
	set QuestionKM to paragraph 1 of clipboardText
	set AnswerKM to paragraph 2 of clipboardText
	tell application "Keyboard Maestro Engine"
	 	 make variable with properties {name:"Question", value:QuestionKM}
	 	 make variable with properties {name:"Answer", value:AnswerKM}
	end tell
end try

In a further action of KM I can access the variable Question, but not the variable Answer. Neither by selecting it from the “Insert Token” menu, nor by %Variable%Answer%.

What’s wrong here? Thanks for any help!

You are deliberately throwing away all information about failure here.

Remove the try/end try, and change the Execute AppleScript to display results in a window and run it and it reports an error trying to deal with clipboard as text because it should be the clipboard.

Alternatively, you can use the Keyboard Maestro Search action to do this directly:

1 Like

Thanks, Peter. That worked. The Regex solution seems to be more elegant though.