Remove a workspace without it being active

You can remove a workspace with bpy.ops.workspace.delete() when it’s active. There does not seem to be a way to remove a workspace when it isn’t.
Other data in has a remove function (for example, while this is not there for the workspaces.

Is the function still missing or am I missing something?

Same problem here.
I’m trying to delete a workspace as the unregister process of an add-on

I tried with:

context.window.workspace = D.workspaces["my_workspace"]
#also with: context.workspace


 override = context.copy()
 override['workspace'] = D.workspaces["my_workspace"]

in both cases the current workspace is deleted

I’m having a similar issue. I want to remove multiple workspaces, but context.workspace won’t update after running workspace.delete() the first time (in a single script), and so only the originaly active workspace is deleted, even after additional calls of 'workspace.delete()` in the same script.

Running has no effect and overrides don’t seem to work either, as posted above.

Looked a bit into this. Apparently the operators don’t consider the context save from the window itself. Instead they first check if the mouse hovers a workspace tab, then grabs the ID from it, otherwise it will always fall back to window.workspace which is the active workspace.

The obvious fix would be to ensure the operators read the context so that it’s possible to pass an override.
So I submitted a patch.


Thank you so much, that is aweome!


In the meantime, I did find a way to delete any arbitrary id block, including workspaces. (and a few others like screens etc.) don’t have a remove() method.

Turns out, it’s possible to feed any id block to as a tuple. It’s also possible to totally wreck the blend file, eg. removing all screens, workspaces, scenes etc :stuck_out_tongue:

import bpy

for ws in
    if ws != bpy.context.workspace:,))

Legandary, I wasn’t even aware of batch_remove()!

workspaces = [ws for ws in if ws != context.workspace]

Thanks again!