How execute script with global shortcut?

Hi there,

can anyone help me out turning the following script into a piece of code so that the script can be executed by a globally working and defined keyboard shortcut?

So far those lines can be successfully be run in text editor, but I better would like to have it installed somehow as an addon.

Thanks in advance.

import bpy

if bpy.context.window.workspace ==['Layout']:
    bpy.context.window.scene =['Scene.001']

if bpy.context.window.workspace ==['Sculpting']:
    bpy.context.window.scene =['Scene.002']

I think you’ll first need to convert your script to an operator, before you can assign it a keyboard shortcut.

There’s some useful information in the “official” add-on tutorial:

There’s also some useful information in this thread on devtalk:

You might also want to check whether your preferred keyboard shortcut is already in use. There’s an add-on “is key free” (included in blender) that allows you to search for a specific shortcut to see what it does already

Thank you very much for your contribution. Looks like I would have to dive deep into python programming, for what I’m not having resources at the moment, just to get back a useful blender feature which I could easily use in 2.79 but not in 2.80 anymore by default:

  automatic "workspace(f.k.a screen) dependent scene loading"

So, upgrading my 2D cutout animation tool and template suite named “Flattiefolks Animation Kit” (being available for free for everyone) from 2.79 to 2.80 & future blender versions won’t happen any soon or at all. :cry:

Any further help welcome.

maybe there is another way that I don’t know about. How did you achieve this in 2.79?

EDIT: Sorry, ignore that. I forgot how 2.79 works. (lol)
I guess you are referring to the way that in 2.79, each workspace could have a different scene open (and changing the scene in one would not change the scene in the others)?
And you want to use that behaviour in 2.8?

I’m not sure what the best way would be to achieve this in an add-on, but I think it could be done

1 Like


This is just a rough 1st attempt (not finished), but if you run this script it approximately replicates the automatic scene-switching behaviour from 2.79 by using a modal operator.

NOTE: there are some problems, including

  • Currently no way to turn it off without closing the .blend file
  • the scenes are not saved in the .blend file
  • This seems to break the feature in 2.8* of automatic switching between different modes when changing workspaces (e.g. changing to sculpt mode when changing to the “sculpting” workspace)
  • While trying to test how it broke that ^, I managed to crash blender, so be careful
    EDIT: the crash was actually caused by a bug in blender, not caused by this script. I’ve reported the bug.

But if those problems could be solved, would something like this be useful for your problem?

import bpy

class ModalWorkspaceScene(bpy.types.Operator):
    bl_idname = "wm.modal_workspace_scene"
    bl_label = "Each Workspace Remembers A Scene"
    def __init__(self):
    def __del__(self):
    def modal(self, context, event):
        if event.type == 'MOUSEMOVE':
            if not (self.lastWorkspace == context.workspace):
                self.keepingTrack[self.lastWorkspace] = context.scene
                if context.workspace in self.keepingTrack.keys():
                    context.window.scene = self.keepingTrack[context.workspace]
                    self.keepingTrack[context.workspace] = context.scene
                self.lastWorkspace = context.workspace
        return {'PASS_THROUGH'}
    def invoke(self, context, event):
        self.keepingTrack = {context.workspace:context.scene}
        self.lastWorkspace = context.workspace
        return {'RUNNING_MODAL'}

def register():

def unregister():

if __name__ == '__main__':

EDIT: there was an error in the last line which prevented the script from running. It previously read bpy.ops.object.modal_workspace_scene when it should have read bpy.ops.wm.modal_workspace_scene. I have fixed that now

1 Like

Thank you so much for helping me on.:slightly_smiling_face:
Impressive! This 1st attempt of yours goes absolutely in the right direction.

:triangular_flag_on_post:Please beware, before investing more of your efforts in this, I have to inform you that I am looking for a free solution that must become freely available for all blender users. That’s because we’re talking about a “Creative Commons Attribution Share­Alike 4.0 License” project I invented to give back my support & gratitude to the blender community. Thanks for your understanding.

So now if you’re further willing to support on finding a acceptable solution on the isssue,
let’s see what we’ve got:

  • a script for selecting workspaces via dropdown menu: :white_check_mark:
    2.80 / How switch scene from text editor?
  • scenes newly created saved in -blend file: :white_check_mark:
  • scenes permanently assigned to workspaces::negative_squared_cross_mark:
  • “assigning scenes to workspaces script” as blender addon or its integration in the first mentioned addon: :negative_squared_cross_mark:
  • bonus: storing & keeping modes (object mode, edit mode, etc. ) within workspace switching (but we also could live without that feature: :negative_squared_cross_mark::wink:

If there’s a chance to get this done, “Flattifolks Animation Kit” might become rescued for the future.:crossed_fingers:

I’m happy for my contributions to this project to be freely and publicly available, as long as they remain freely and publicly available.

To that end, I propose that any further code that I contribute to your project be published under GPLv3 license. (This also ensures that it complies with blender’s GPLv3 license)

As far as I can tell, GPLv3 and CC BY-SA 4 licenses are compatible so this should not be a problem.

Would this be acceptable to you?

Having found this thread, and having now downloaded and tried your animation kit, I think I understand your problem much better. :slight_smile: I understand now why it is so important for you to restore the 2.79 way of working to 2.8*

I am happy to help you solve your problem, and I think I know how to fix the last few issues…
I propose the following:

  1. a pair of python scripts which will read the screen/scene pairs from the 2.79-compatible blend-file, and then set up the same workspace/scene pairing in 2.8 using custom properties to store the scene name in each workspace. By storing the scene name in a custom property, the information will be saved in the .blend file, so this would only need to be set up once.

  2. Combining all of the scripts and work-arounds you have found into one add-on, which can be used to replicate the functionality of 2.79 (i.e. no workspace tabs, automatic scene-switching, and selecting workspaces from a drop-down menu.)
    This add-on could be published separately (for the benefit of others who want to use old 2.79 way of doing things), but also it could be bundled with your animation kit.

What do you think?

This is great news - very helpful and very kind of you, thank you!

I think your suggested approach seems to be exactly the right and reasonable
way to handle this & to achieve results from which all blender users could benefit,
no matter if they are into 2D, 3D animation or whatever when choosing blender.
(By all means you also shall be credited for work that’s done by you.)

“To that end, I propose that any further code that I contribute to your project be published under GPLv3 license. (This also ensures that it complies with blender’s GPLv3 license)
As far as I can tell, GLPv3 and CC BY-SA 4 licenses are compatible so this should not be a problem.
This add-on could be published separately (for the benefit of others who want to use old 2.79 way of doing things), but also it could be bundled with your animation kit.”

100% agreed, also your two points roadmap sounds perfect & wise.

Again thank you for your support, :sparkling_heart:BA community.


I’ve written two python scripts which implement the first part of my roadmap.

I’ve also setup a github repository for this project, I’ve called it “scene-per-screen”.
(Not strictly necessary, but it gave me an excuse to learn how github repos work, which is something I’ve been meaning to do for a while now)

Sadly I’m quite busy at the moment (hence the slow progress), but hopefully I will have some time later this week to finish it off


I finally found some time to combine all the scripts and pieces of code into an addon. You can get it from the github repo I made.

(I used my real name in the code, instead of my blenderartists username, so that’s why the name is different.)

The addon and the scripts seem to work, as far as I can tell. But you should test yourself to see whether this is behaving the way you expect it to.

Currently there is one really annoying problem with this addon which is that the automatic scene-switching has to be manually enabled from the preferences every time blender is re-started. I’ll probably take another look at it tomorrow with fresh eyes and try and come up with a better solution. At the very least, a keyboard shortcut would be better than having to click button in the preferences every time…


Many thanks for your outstanding work! Must be Xmas around, huh? :wink:
(my ba profile picture surprisingly even got a christmas cap)

After a first quick test, your result already looks very promising.
Hope I was using the proper method while testing it with an empty blender start file:

1.) unzipped “”
2.) installed “” as Addon in blender 2.80
3.) checked “Preferences: enable automatic scene switching”
3.) used CTRL+SHIFT+SPACE for dropdown menu workspace switching
4.) created more scenes & changed/assigned scenes to individual workspaces
5.) got working result

For me it seems these two 2.79/2.8x import/export scripts no longer have to be involved for the procedure, am I right or wrong?

To not get lost or confused which workspace has become the actual selected one,
one suggestion has come to my notice: could you perhaps implement the active workspace name to be shown at top bar?

I will also take some more time for testing around the edges and will be in touch.


Yeah, that sounds right for an empty file

The two scripts are for saving an existing configuration from a blender 2.79 blendfile, and loading it into the same blendfile in 2.80 in a way that can be read by the add-on

I agree that would be useful.