2.80 / How switch scene from text editor?

Many thanks, this works very well, unfortunately only when triggered via “Run Script” in text editor. So far I wasn’t successful to put your help into addon form, instantly checking and switching automatically scenes dependently to the active workspace.

If I only could integrate your piece of code somehow into that following little addon which is available so far and lets you select workspaces via drop down menu (global shortcut: SPACE+CTRL+SHIFT):

bl_info = {
"name": "workspaces dropdown menu",
"category": "ui",
"blender": (2, 80, 0)
}

import bpy


class WORKSPACE_OT_select(bpy.types.Operator):
    bl_idname = "workspace.select"
    bl_label = "Select Workspace"
    bl_description = "Select workspace"
    bl_property = "workspace"

    enum_items = None

    def get_items(self, context):
        if WORKSPACE_OT_select.enum_items is None:
            enum_items = []

            for w in bpy.data.workspaces:
                identifier, name, description = \
                    w.name, w.name, w.name
                if context.workspace.name == identifier:
                    name += "|Active"
                enum_items.append((
                    identifier,
                    name,
                    description))

            WORKSPACE_OT_select.enum_items = enum_items

        return WORKSPACE_OT_select.enum_items

    workspace = bpy.props.EnumProperty(items=get_items)

    def execute(self, context):
        if not self.workspace or self.workspace not in bpy.data.workspaces:
            return {'CANCELLED'}

        context.window.workspace = bpy.data.workspaces[self.workspace]
        return {'FINISHED'}

    def invoke(self, context, event):
        WORKSPACE_OT_select.enum_items = None
        context.window_manager.invoke_search_popup(self)
        return {'FINISHED'}


addon_keymaps = []


def register():
    bpy.utils.register_class(WORKSPACE_OT_select)
    
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(
        name='Screen Editing')

    kmi = km.keymap_items.new(
        WORKSPACE_OT_select.bl_idname, 'SPACE', 'PRESS', 
        ctrl=True, shift=True)

    addon_keymaps.append((km, kmi))


def unregister():
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
        
    addon_keymaps.clear()
    
    bpy.utils.unregister_class(WORKSPACE_OT_select)


if __name__ == "__main__":
    register()



Sure, in any addon line you would have to define which scenes and workspaces exist and how they are assigned to each other.

I don’t want to take advantage of anyone’s help, but i would be really grateful for any useful suggestions.