Posted on 23 August 2005, 23:46

Workspaces in BBEdit

Here's a script I use to save document windows in BBEdit 8+. It's the way I believe "Workspaces" should work. The script is a slight modification of Johan Solve's Document workspace script. The modifications respect multiple documents within a window and reset the workspace before a new save.

property workspace : {}

tell application "BBEdit"
    if (count text windows) = 0 then
        -- if we have no open documents, we always load the workspace
        set choice to "Load"
    else
        -- ask user if we should save or load the workspace
        set choice to (button returned of (display dialog \
        "Do you want to save or load workspace?" \
        buttons {"Cancel", "Load", "Save"} default button "Save"))
    end if
    if choice is "Save" then
        -- reset workspace
        set workspace to {}
        -- save current windows
        repeat with thiswindow in text windows
            set documentlist to {}
            -- save current documents in each window
            repeat with thisdocument in (text documents of thiswindow)
                if on disk of thisdocument then
                    set documentlist to documentlist & {file of thisdocument}
                end if
            end repeat
            set workspace to workspace & {documentlist}
        end repeat
    else if choice is "Load" then
        -- open last saved windows
        repeat with thiswindow in workspace
            open thiswindow opening in new_window
        end repeat
    end if
end tell

Add a comment?

Sign in to add your own comments.