Keyboard Maestro 8.0.3 “Add only new folder names to a file
I have a text file containing a directory tree. In order to automatically update the list of folders when a new folder is created on the disc I would like KM to read the text file, go through a folder recursively and check if the specific folder already exists in the text file and add it to the end of the file if the folder does not exist.
Unfortunately I am struggling with making the test if the folder already exists and react accordingly, and would appreciate some help to make it work. Any ideas what goes wrong?
As near as I can tell, searching and replacing a variable with identical values will simply end up copying that variable to wherever it is replaced (the found variable in the case of your original macro) so found will never end up starting with "nothing found" even when it's supposed to. I suspect that may have been the primary reason why your macro didn't work the way you expected.
Here's another way I figured out that seems to fit your requirements. Every time a new folder (or file, so be wary of that) is added to the folder (Desktop, in this case) it checks the text file specified in the beginning for the number of times the path of the newly added folder/file matches a line. If the number is not 0 (i.e. one or more matches has been found and the folder/file already exists) it leaves the file alone; if it is 0, then it appends the new folder/file's path to the text file.
Unfortunately this version can't make use of the TriggerValue token to automatically add entries to the text file, but it should search every folder (and file) recursively in the folder you specify, including its subfolders, and add the path of any newly added folder or file however you decide to trigger it. Give it a try and let us know if it still doesn't do what you want.