Server script to provide BBEdit with functionality to store and restore currently open text windows.
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).
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.
BBWorkspace, and the scripts that call it, can be placed anywhere on your computer.
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.
Stores the workspace as a record.
If the 24U Appearance OSAX is installed, progress messages are displayed.
Restores the workspace.
If any windows are already open, confirmation must be given to continue.
Stores the workspace under a new name.
Opens a stored workspace after prompting for its name.
Sets the preferences for how the server script behaves.
Values: Restore none, Restore bounds only, CustomiseÉ
Determines which properties of windows should be restored. By default, set to "Restore bounds only". If set to "CustomiseÉ", a list of properties is presented to select from.
Values: Restore, Discard
Determines whether unsaved changes to files should be restored. By default set to "Restore".
Values: Restore, Discard
Determines whether unsaved files should be restored. By default set to "Restore".
Values: Show, Do not show
Determines whether progress messages should be displayed or not. Only applicable if the 24U Appearance OSAX is installed. By default is set to "Show".
Values: Never, Every 2 minutes, Every 5 minutes, Every 10 minutes
Determines whether the workspace should be stored automatically, and if so how frequently. By default is set to "Never".
Returns the record of the currently stored workspace.
Sets the workspace to the new record.
Clears the currently stored workspace.
Clears all currently stored workspaces.
Returns the record of the currently stored workspace as a string. Useful if you want to back up the value of the current workspace. Can be reinstantiated using code like this: set newWorkspace to run script "return " & workspaceStoredAsString
Returns the list containing all currently stored workspaces as a string. Useful if you want to back up all the current workspaces. Can be reinstantiated in the same manner as GetWorkspaceAsString()'s output.
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)
Just stores the current workspace. Invoke it manually or create a menu script and attach it to the "Quit" command.
Prompts for a name, creating a new workspace if that named workspace does not already exist, and then stores that 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
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.
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.
Resets the current workspace to be empty.
Clears every workspace that you have created.
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.
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
Alex Robinson, <bbworkspace[@]alex.cloudband.com>
2004/09/15
Added multiple workspaces and renamed from BBEditWorkspace to BBWorkspace.
Initial version.