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
- Download Tinderbox Action Code in BBEdit.popclipext.zip (18.4 KB)
- Unzip
- Double click
- Choose
Install "Tinderbox Action Code"
Optional:
- 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
try
----------------------------------------------- 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
activate
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 theLanguage-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 seeFile 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