BBWorkspace 0.91

Server script to provide BBEdit with functionality to store and restore currently open text windows.

Download

Download BBWorkspace

The Problem

BBEdit has no workspaces (well it does now, as of version 8.0, but that's not what most people understand by a workspace). It does not remember what windows you had open the last time you ran it. It does not remember any changes you made to files but did not save - consequently if you have to quit you have to make a decision about what you want to do with all those unsaved changes and new files which have not yet been saved. And as often as not, if you have to quit, you're in a rush and the last thing you want to have to deal with is figuring out what needs keeping and what can be junked.

Of course, if you never need to quit then this is a non-problem. For me, with an iBook whose battery fails to provide power (despite being fully charged) and which crashes with an all too depressing frequency, it's downright infuriating. (Update: the iBook is dead - I now have a new one and it's only been back to Apple for cataclysmic hardware failure once).

The Solution

BBWorkspace is a stay-open applet (or server script) written in AppleScript which enables BBEdit to behave as if it has workspaces. Its subroutines are explained below and applescripts in this folder give examples of how it can be used.

Installation

BBWorkspace, and the scripts that call it, can be placed anywhere on your computer.

Usage

You can customise scripts for your own purpose, but the scripts "Restore Workspace" and "Save Workspace and Quit BBEdit" are sufficient for a basic store on quit and restore on relaunch functionality if you only need a single workspace.

Subroutines

Window types restored

Flaws

Although BBWorkspace can restore unsaved changes to files, that's all it does. As it simply replaces the contents of the file with the stored version, there is no fine-grained step-by-step undo history available. Consequently undoing the changes will revert straight back to the saved file.

A combination of lack of support for AppleScript to access BBEdit's preferences and the fact that the properties of a window contain certain properties which are either read-only or means that the user must make a decision about which properties to restore. If only local files are involved, BBEdit's "Honor saved state" can be relied on. Similarly, unless you like to vary the options for every file drastically, your basic settings should suffice and all that BBWorkspace need provide for you are the bounds of each window.

It would be possible to add support for File Group and Disk Browser windows in addition to Text windows - however these window types are simply ignored. Personally I am more interested in FTP Browser windows but these appear to be beyond the reach of BBEdit's current AppleScript implementation.

STOP PRESS: The new multi-tabbed windows in BBEdit 8.0 cause a problem too - only one document is stored and thus recovered for each window. No doubt this is trivially easy to fix, but I currently don't have the time.

If BBWorkspace fails at any point, that's it. There's no fancy error checking or data backup. The good news is that it doesn't affect your saved files and if anything does go wrong, the only data you will lose is that which was unsaved and is no longer in an open window.

Memory could be an issue too if you have lots of workspaces with lots of documents in them with lots of text in them since BBWorkspace just stores everything in a couple of records. Which could end up being mighty big records. It's never been an issue for me, but then again, I've never tried to use BBWorkspace with more than 20 or so open documents. If this is a serious problem, BBWorkspace will have to become a proper little app and store the data more rigorously. (And the next day Bare Bones will announce real workspaces in BBEdit)

Of course, the fact that such a solution is necessary in the first place is an enormous flaw, and one which BareBones will see fit to remedy in the near future. (As well as provide a decent mechanism for writing language modules that are as easy as, for instance, those for jEdit) (Oh, they've added one, but it sucks. Well, at least it does for someone like me who wants to create a module for Mason requiring support for markup and embedded languages - it took me 20 minutes to knock one up for jEdit)

Bundled Scripts

Save Workspace

Just stores the current workspace. Invoke it manually or create a menu script and attach it to the "Quit" command.

Save Workspace As

Prompts for a name, creating a new workspace if that named workspace does not already exist, and then stores that workspace.

Open Workspace

Presents a list of workspaces and then opens the chosen one.

NB. any other windows that are currently open will end up becoming part of the opened workspace when it is next saved

Restore Workspace

Put this in your "Startup Items" folder and BBEdit will recreate the last stored workspace when you launch it. Alternatively, use it to undo any changes you've made since you last stored.

Save Workspace and Quit BBEdit

Does the same as "Save Workspace" but, surprise surprise, then quits BBEdit. For those who don't want to create menu scripts. Either just run it manually or put it in your "Scripts" folder and assign the keystroke cmd-Q to it.

Reset Workspace

Resets the current workspace to be empty.

Reset All Workspaces

Clears every workspace that you have created.

BBWorkspace Preferences

Allows you to change BBWorkspace's preferences - see above for details. With the 24U Appearance OSAX, you get a proper preference panel - without it it's a wizard-style affair.

24U Appearance OSAX

This OSAX is not bundled with the script. However it is heartily recommended since it provides a compact interface for the WorkspacePreferences() subroutine and also, more importantly, message windows to show progress when storing or restoring. Although recommended, it is not essential for the operation of BBWorkspace.

Further information, and the OSAX itself, can be found at http://www.24usoftware.com/AppearanceOSAX

Author

Alex Robinson, <bbworkspace[@]alex.cloudband.com>

2004/09/15

License

Public Domain Dedication
This work is dedicated to the Public Domain.

Version History