Working with external files for the TBX action code

If you collect more and more useful action code functions over time, it is more convenient to store this collection only once and still be able to use it in all your Tinderbox files. If you copy and paste the action code back and forth between the TBX files, it quickly becomes confusing. Instead, you can put the code into external text files and then use these files, which are only stored once, in all your TBX files.

In addition, you can now use BBEdit together with Pete’s great Langugage module for editing the action code. This also makes your work easier.

To use my external code lib you have to:

  • copy the note “cExternalCode” into your /Hints/Library“ folder in your TBX file (it has to be stored inside of TBX)

  • copy two stamps “ClearWatchFolder” and “InitializeExternalCode” into your TBX file

  • edit the path in the note „cExternalCode“ in the function “externalCode_Init_db” look for this line:

if($WatchFolder("/ExternalCode") == ""){$WatchFolder("/ExternalCode") = "/Users/YourName/Documents/Tinderbox/Code";};

Change “/Users/YourName/Documents/Tinderbox/Code” to the path of any folder on your Mac. This folder should contain all your external action code files. Do not proceed until you change the path here!

  • run the stamp „InitializeExternalCode“ once

That’s it!

Some additional comments:

  • your external Code files should be named like “This”. For example I have files like “Debugger”, “LinkManager” or “Tools” there. Don’t use a file extension like “.txt” (you are on a Mac…).

  • If a new file will be added to you external code folder in the Finder, everything in TBX will run automatically. The new file will get added to your Library (click on the /ExternalCode note to run the code in the $Edict immediately).

  • If a file will be deleted in you external folder in the Finder - again everything in TBX will run automatically. The existing note in your Library will be removed.

  • If you update the code in an external file, you should delete the corresponding note in the /ExternalCode container in your TBX file. This forces the script to grab the external file again and update the Library. More easy: run the Stamp “ClearWatchFolder” on the /ExternalCode container. That’s all you need to get the latest version of your code into TBX.

  • If your code file contains a function named “filename_Init_db()” (for example for my file named “Debugger” it would become “debugger_Init_db()”) this function could be used to initialise a new file. There is a flag called “ExternalRunInit” in the “gExternalCode” note. You have to check this option to get a call to the initialise function. This option is in an early state of development…

  • check the action code before you copy it into an external file. One error and the complete code inside of the file will be ignored in TBX.

Have fun.

ExternalCode.tbx (182.3 KB)

4 Likes