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.