Operator Scope of Action:
Operator First Added:
Operator Last Altered:
Operator Uses Regular Expressions:
Operator Has Optional Arguments:
Function [other Function type actions]
Conditional Group [operators of similar scope]
Dictionary, Set & List operations [other Dictionary, Set & List operations operators]
As at baseline
The links() operator builds a List from a collection of links. It selects the note(s) whose links should be inspected. The scope is one or more items (defining scope), but note the scope argument is not fully evaluated, so only use simple expressions. scope never matches aliases. When using links() in the context of an agent's action, remember that aliases can have different basic links to their originals. Therefore, it is likely that act action using 'this' will want to replace it with 'original' as the scope when re-used in an agent action.
The directionStr argument filters the directionality of the links collected. It is mandatory, and should not be quoted. It can only be is one of these values:
The optional linkTypeRegex argument is evaluated as a regular expression. Although the most normal usage will be as a literal string of a single link type name. Regex use allows for It collects only links of a specified link type, or such type(s) as match the linkTypeRegex regex amongst the link type names defined in the current TBX. Regular expression wild-card characters are permitted and retain their special meanings. If the linkTypeStr value contains white space or periods, it must be enclosed in double quotes:
If linkTypeRegex is left empty, links of all types are collected except prototype links. Prototype links are always omitted. Single quotes can be used to enclose linkTypeRegex but if the quoted string includes a single quote this must be backslash-escaped or double quote used instead:
links.outbound."Peter's place".$Name OK
links.outbound.'Peter's place'.$Name wrong
links.outbound.'Peter\'s place'.$Name OK
The is evaluated for regex.
The attributeNameStr argument is the name of the attribute whose values are to be collected in the result. An attribute reference, e.g. $Name("nextSibling") is invalid, the command work but the reference is ignored and the stated attribute for the linked note is used.
constructs a set of all the titles (from Name attribute) of notes that are linked to the top-level note named 'config' via links with the link type 'supports'. This does the same but for all link types;
For multi-word link type names use quotes (or if using regex characters):
Whilst it is likely that 'Name' will be the most usual value for attribute, it can be any currently defined attribute:
collects a list of values of the attribute 'SchoolName' for notes that have an inbound link to the current note of link type "went to".
Beware when using a TBX that has notes with duplicate (same) $Name values. As a set contains unique values, if several notes have identical names, then
will list the distinct Names only once in MySet, and so the latter will have fewer values than the actual number of matching links. In the same scenario:
will create a list containing duplicates.
The format() or List.format() operators can help make more use of links() data during export, e.g. as lists or lists of links. Internally, if analysing links and there is no real need to keep set-type data, using agents employing linkedTo() and linkedFrom() will find most of the same data as links() can provide.
The links() function can be chained by dot operators pertinent to use with List type data. But, as links() uses dot-chained arguments, it is necessary to use parentheses to chain other dot operators. Thus, to get a count of the number of linked items found:
In addition, the use of parentheses helps make sense of the intended order of execution of the tasks chained to links():
More examples of links() syntax:
links("A note;A different note").inbound."*untitled".$Path
Working with links
If needing to return multiple items from linked items or to do more complex link-based work, see the eachLink() operator which offers a wider range of options.