Set link type automatically based on container of destination notes?

I added some notes to your document and reset the agent query to:

$TextLinkCount(original)>0

For ease of testing, the above matches any note with 1 or Text links ($PlainLinkCount), for as we know know all links created via the ‘zip’ method are, in Tinderbox terms, Text links. This query ensure you don’t you won’t match notes with only Basic type links.

The agent action we came up with earlier is:

eachLink(aLink,original){
   if(aLink["type"] == "*untitled"){
      aLink["type"] = "reference";
   }
};

Can you see the problem? If I have an untiled link from Note 4 to Note I, this incorrectly resets the link type as it fails to check the destination is in /Sources. We need to be more specific, we need to test not only the the link type but also that the destination includes the path /Sources and that anchor is not empty (in which case the link must be a basic link , as only Text links have anchor text).

The action becomes:

eachLink(aLink,original){
   if(aLink["type"] == "*untitled"&aLink["destination"].contains("/Sources")&aLink["anchor"]!=""){
      aLink["type"] = "reference";
   }
};

In my test there are the following links:

  • Source 1. ‘untitled’ text link to ‘Note 3’: should be unaffected.
  • Source 2. ‘untitled’ text link to ‘Source 3’: should change to ‘reference’.
  • Source 3. ‘untitled’ basic link to ‘source 2’: should be unaffected.
  • Note 1. ‘untitled’ text link to ‘Source 1’: should change to ‘reference’.
  • Note 2. ‘disagree’ text link to ‘Note 3’: should be unaffected.
  • Note 3. ‘disagree’ text link to ‘Note 2’: should be unaffected.
  • Note 4. ‘untitled’ text link to ‘Source 2’: should change to ‘reference’.
  • Note 5. ‘untitled’ text link to ‘note 2’: should be unaffected.
  • Note 6. ‘untitled’ basic link to ‘source 2’: should be unaffected.

Here is my test file in two versions:

Look at both, and check their links against the results I listed above: remember use Browse Links with the original note selected and not the alias in the agent. Then, in the ‘before’ version, turn the agent query on. To to this, in the Query Inspector, open the Priority pop-up menu bottom left, change the selection from ‘Off’ to ‘Normal’. Allow a few moments for the agent to run, then check the links and note any changes.

1 Like