Tinderbox Forum

A BBEdit Codeless Language Module for Tinderbox Action Code

This is a BBEdit Codeless Language Module (CLM ) for Tinderbox Action Code.

It makes it possible to edit Tinderbox Code with all the nice things BBEdit offers:

  • auto completion
  • auto indentation
  • code folding
  • custom color scheme
  • custom font and font size

Installing the Codeless Language Module

  • Select BBEdit menu BBEdit > Folders > Language Modules
  • Download Tinderbox.plist.zip (4.5 KB)
  • Unzip and move the CLM
  • Restart BBEdit

Making current User Attributes available

BBEdit CLMs are only loaded on BBEdit’s start, which means it’s not possible to add or update a Tinderbox’s current User Attributes in the CLM without restarting BBEdit.

As restarting gets quite annoying I decided to use a workaroud. BBEdit Clippings are immediately availabe in BBEdit, which means they can be used to make User Attributes available for auto completion without restarting BBEdit.

To add User Attributes as BBEdit Clippings we need to run a script. I use a PopClip extension (see below) that opens a new BBEdit document for selected code and adds User Attributes as Clippings. If you don’t use PopClip or don’t want to use the PopClip extension then you need to run the script (see below) manually, e.g. via Alfred or Keyboard Maestro.

The PopClip extension

PopClip is an app that appears when you select text with your mouse. There’s a free trial.

The “Open Tinderbox Action Code in BBEdit” PopClip extension

  • opens a new BBEdit document for selected code
  • adds Tinderbox’s current User Attributes as BBEdit Clippings

Installing the extension


  • Click the pencil button at the bottom of PopClip’s extensions menu
  • Drag the extension to where you want it to appear

The standalone AppleScript

If you don’t use PopClip or don’t want to use the extension you can use this script to add Tinderbox’s current User Attributes as BBEdit Clippings. Run it after you’ve added, deleted or renamed User Attributes.

Click to see the script
-- Create BBEdit Clippings for current Tinderbox's User Attributes

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

	----------------------------------------------- Create path to BBEdit's Clippings subfolder ------------------------------------------------
	-- NOTE: The folder theUserAttributesClippings_Path will be DELETED! 
	-- If you need to adjust the path to BBEdit's application support folder be VERY CAREFUL!
	-- Make sure that the path ends with "/Clippings/Tinderbox/User Attributes/". Otherwise you'll delete BBEdit's application support folder!
	set theUserAttributesClippings_Path to POSIX path of (path to application support from user domain) & "BBEdit/Clippings/Tinderbox/User Attributes/"
	------------------------------------------------------------- Get User Attributes --------------------------------------------------------------
	tell application "Tinderbox 9"
		if not (exists front document) then error "Please open a Tinderbox document"
		tell front document
			set theAttributes_UserAttributes to name of user attributes
		end tell
	end tell
	----------------------------------------------- Prepare User Attributes for Auto Completion ------------------------------------------------
	set theAttributes_UserAttributes to my tid("$" & (my tid(theAttributes_UserAttributes, linefeed & "$")), linefeed)
	--------------------------------------------------------- Delete Clippings subfolder ----------------------------------------------------------
	set theUserAttributesClippings_URL to current application's |NSURL|'s fileURLWithPath:theUserAttributesClippings_Path
	set successDeleteDir to (current application's NSFileManager's defaultManager()'s removeItemAtURL:(theUserAttributesClippings_URL) |error|:(missing value))
	--------------------------------------------------------- Create Clippings subfolder ----------------------------------------------------------
	set {successCreateDir, theError} to current application's NSFileManager's defaultManager's createDirectoryAtURL:theUserAttributesClippings_URL withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
	if theError ≠ missing value then error (theError's localizedDescription() as string)
	-------------------------------------------------------------- Create Clippings ---------------------------------------------------------------
	set theAttributes_UserAttributes to current application's NSMutableArray's arrayWithArray:theAttributes_UserAttributes
	repeat with i from 0 to ((theAttributes_UserAttributes's |count|()) - 1)
		set thisUserAttribute to (theAttributes_UserAttributes's objectAtIndex:i)
		set {successCreateFile, theError} to (thisUserAttribute's writeToURL:(theUserAttributesClippings_URL's URLByAppendingPathComponent:thisUserAttribute) atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(reference))
		if theError ≠ missing value then error (theError's localizedDescription() as string)
	end repeat
on error error_message number error_number
	if the error_number is not -128 then display alert "Error: \"addBBEditClippingsForCurrentUserAttributes\"" message error_message as warning
	error number -128
end try

on tid(theInput, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	if class of theInput = text then
		set theOutput to text items of theInput
	else if class of theInput = list then
		set theOutput to theInput as text
	end if
	set AppleScript's text item delimiters to d
	return theOutput
end tid

Customizing the Codeless Language Module

  • Select BBEdit menu BBEdit > Preferences
  • Go to Languages
  • Click + in the Language-specific settings section
  • Select Tinderbox

Tab “Editor”

  • Click tab Editor
  • Choose a Font and Font Size
  • Turn on Automatic completion
  • Turn on Auto-indent

Tab “Display”

Using another color scheme

  • Click tab Display
  • Choose a color scheme

Using a custom color scheme

  • Select BBEdit menu BBEdit > Preferences
  • Go to Text Colors
  • Click New…
    This is important, without it you’ll overwrite the current color scheme.

The CLM matches BBEdit syntax colors to Tinderbox Action Code like this:

  • Language keywords : System Attributes
  • Predefined symbols : Operators
  • File includes : if/else/true/false
    You have to scroll down to see File includes.

If your changes aren’t picked up immediately restart BBEdit.

Remember to set the color scheme back to your default color scheme.

  • Click tab Display
  • Choose your custom color scheme

Very impressive work - great - thanks a lot!

1 Like

If you’ve downloaded the PopClip extension please download it again.

I created a small demo to be used with your great extension to my favourite text editor. With this setup it is easy to maintain the code snippets for TBX as external text files and reuse them in several TBX projects. All you need is a WatchFolder to import those files.
There is one note called “gPreferences” and there for each and every note I store two values in a dict: the attribute ($Edict, $OnAdd…) the code should be copied into and the name of the note where this attribute is located. That’s all.

“TestTarget01” and “TestTarget02” are the notes where the action code should run. “WatchMe” is the folder with the external content and the action code snippets.

The $Edict of the “WatchMe” note contains:

  var theName =$ExternalCode("/gPreferences")[x];
  var theTarget =$ExternalTarget("/gPreferences")[x];
  $Edict(x) = "$" + theTarget + '(\"' + theName + '\")=$Text' + ";";

Again - thanks a lot for your CLM module.

ExternalCode.zip (33.0 KB)


Updated the CLM for Tinderbox 9.1. Please download it again.


Updated the CLM for Tinderbox 9.2.

Tinderbox.plist.zip (4.8 KB)


Updated the CLM for Tinderbox 9.3.

Tinderbox.plist.zip (4.8 KB)

1 Like

Yay! Thanks. As Tinderbox uses the ‘tbx’ extension unopposed, it might be useful to add extension detection and suggested new file save extension (for files with this language type set) for ‘tbx’.

I believe the extra syntax is this (per Barebones’ CLM notes):


Though I’m not 100% sure where in the plist it goes! Note, the use of a prefix period in one key’s value and not the other is as per the BBEdit docs. Tried adding at the end (inside outermost <dict> element) … and it works. :slight_smile:

Here is where i put the extra:

So, here is the amended version (unzips to ‘Tinderbox.plist’ ready for use): Ed- Tinderbox.plist.zip (4.9 KB)

What does it alter? If the amended CLM is used:

  • Opening files with a ‘tbx’ extension will automatically select the Tinderbox ‘language’ for code hinting. Of course, as presently, the current selection can be altered from the language pop-up in the left end of the document status bar. Not tested, but per docs, the ‘tbx’ match is case-insensitive
  • Saving a new file for the first time, if the language selected is ‘Tinderbox’, BBEdit’s default filename selection will include a ‘.tbx’ extension.

Above addition is minor, a their remains a big thank you for doing all the real heavy lift of making the file. Some years back, I tried a CLM for Tinderbox … and it ended badly :frowning:

Nice! I’ll try that later. The CLM was of course only possible with your incredibly useful aTbRef, thanks again and again :slight_smile:

I’ve spent the last hours searching for a way to add designators to the CLM, however some of them conflict with operators, e.g. Date.day (operator) vs. day (designator). In general it should be possible to distinguish between both by using regex (the regexes work in TextSoap and BBEdit), however I didn’t find a way to make it work in the CLM. I’ll probably reach out to BBEdit support as it would be nice to also have designators highlighted.

As well as support, there is a Google.groups forum at https://groups.google.com/g/bbedit which has helped me occasionally in the past (esp. when first learning about grep and regex.

I agree that having designators would be cool. I think the CLM colouring is essentially using string match so ‘today’ in $Text would likely be marked. As the point of the CLM is colour code such accidental colouring is not really problematic IMO.

IF going down that path, I’m not sure I’ve an exhaustive list of all the time/date strings accepted (if you include those) but i think they are case-insensitive and allow for singular and plural, i.e. any of day days Day Days etc. for a day scope and so on. That said there has been discussion as to whether these are designators or keywords.

As regards scope designators (item or group scope), I believe those are correct in aTbRef are the two linking-only designators source and destination.

Hood up on aTbRef as I struggle to get a better pan-document method for describing operator arguments, their purpose and their syntax. In some cases a description of just one of the two facets is insufficient data to guide the new/occasional user. Ideally I’d where possible link through to (or ^include()^) a single definition, e.g. of how scope is defined, or the how a string literal value is entered, etc.