Tag jpegs with folder's name

I want to set up a rule that will tag every jpeg with the "X" tag if the folder containing that jpeg has a "X" in its name. How do I set up that rule? The jpegs are organised in subfolders.
simply useful mac software
https://www.noodlesoft.com/forums/
if (all) of the following conditions are met for (the file or folder being processed):
extension is JPEG
if (all) of the following conditions are met for (its enclosing folder):
name contains "X"
Do the following to the matched file or folder:
rename...