What you’re doing is probably one of the more complex things you can do in a Tinderbox action (even if unwittingly) because:
- Agents act on aliases, though luckily we now have
linkFromOriginal which eases part of the issue
- In a
find() the ‘this’ designator has a different meaning. To use a value from the note/alias being processed within the
find() query, you need to use the ‘that’ designator.
- Unlike an agent query a
find() query doesn’t de-dupe. Instead it returns the paths of the original and/or all aliases in query scope, so if trying to link to a single instance of the target (be it an alias or an original) you need to specify that particular object otherwise the link/unlink action will create/remove multiple links.
As to this code:
The ‘.’ in a regex pattern means any character except a new line. But because it’s not within the regex pattern (contain() takes a quoted regex, it’s anyone’s guess as to how Tinderbox will parse this - i.e. the outcome can’t be predicted.
Furthermore, I’m now sure you’ve correctly understood how var() works:
I don’t think a var variable name can use a $prefix nor should it (case-sensitively) match the name of an existing reference (see the link above to documentation of the var() function). Don’t assume the $ prefix is the same of [some computer language] but rather read tutorial PDFs in the apps Help menu to understand how Tinderbox’s action code works.
I don’t have enough info to properly replicate your document but I think your whole first code example should be replaced with this:
Separately, depending on the number of child notes in ‘home’ I’m not sure how well this agent-approach scales. Unless every child** of ‘home’ is a target for linking, I’d consider using a common prototype (or limited set of prototypes) that apply only to the target group of notes. Also, given the action runs a find() query using a regex operator like .contains(), I’d consider moving the code into an edict run in the reference notes (doing so via a prototype).
** note that
inside() tests only children of the target container, and not those children’s descendants.
If still stuck, could you consider posting a link to a small TBX that demonstrates your problem space so we’ve a more complete common reference from which to help you.