Find a word in a list and use the result to do an action

Hello.
I’m sure this has a very simple solution, but… I’m not there yet…
I;m building a macro and stuck in the middle.
I have a list of words (I can use Word; Excel; Text Edit; Notes or any other application, if there’s any difference for KM):
Apples
Bananas
Oranges
Potatoes

I need to check the list: if it contains Papaya then do X if it doesn’t, paste Papaya at the bottom of it.

I know how to do everything except the above. I guess I use somehow the result of the search as a variable and then incorporate it in an If/Then Else action.
But, I have no idea how to turn the result if the search and also how to use it in the If/Then.
Would be very appreciative of help!
Thanks in advance.
Saul

You need to get the text into KM to check it, and the easiest way to do that is to copy it and read it from the clipboard. Here's a quick sample macro to get you started:

[Example] Find a word in a list and use the result to do an action.kmmacros (3.2 KB)
52 AM

1 Like

You need to get the FilePath to your text document. I have just "hard coded it" in this example.

/Users/owl/Desktop/PapayaTest.txt

That FilePath is assigned to a Variable (myFilePath)
Then you create a Variable (myLines) that contains the contents of the text document
Set a Variable (hasPapaya) to False as the default

Then go through all the lines of the Variable (myLines) and you are going to look for Papaya
If you find it on any line, then Variable hasPapaya will be set to True.

Now what you do is determined by the value of hasPapaya.
If it is True, then an Alert will tell you (and you can do X)
If it is False, then Append Papaya to the end of the document.

180320_1645Pap

1 Like

My original reply did not show the innards of this Action.

1 Like

Thank you glick and rlivingston, very much appreciated.
Tomorrow will try to understand and implement. Will keep you posted.
Saul

1 Like

Hello gglick and rlivingston.
Took me sometime, but combining what you both wrote+ researching the forum+ watching some tutorials on youtube (thanks Dan Thomas and JMichael TX for the time you took with the tutorials) I succeeded to create the macro I needed and on the way learning some new things.
Very very much appreciate your time and your willing to help guys!
Thanks a lot.
Saul

1 Like