# Is it possible to give a shortcut to a specific screen layout?

I know about the shortcut Ctrl + Left / Right arrow to switch between the screen layouts, but that forces you to go through all of them if you have many.

I'd like to give a screen layout (not only to an editor) a single shortcut like:

F1 = 3D View Full

F2 = Animation

F3 = Compositing ...

Is it possible via User preferences > Input? If so, what is the exact code operator I should put in the key map? (like "screen.screen_set" but with the specific name of my screen layout)

Thank you.

An operator to set screen by name.

import bpy
from bpy.props import StringProperty

class SCREEN_OT_set_by_name(bpy.types.Operator):
"""Change Screen by Name"""
bl_idname = "screen.set_by_name"
bl_label = "Set Screen by Name"
bl_options = {'REGISTER', 'UNDO'}
name = StringProperty(default="",
description="Set the Screen by name")

@classmethod
def poll(cls, context):
return context.screen is not None

def execute(self, context):
to_screen = bpy.data.screens.find(self.name)
if to_screen >= 0:
# context.screen
from_screen = bpy.data.screens.find(context.screen.name)
delta = to_screen - from_screen
if not delta:
return {'CANCELLED'}
sign = abs(delta) / delta
delta = abs(delta)
for i in range(delta):
bpy.ops.screen.screen_set('INVOKE_DEFAULT', delta=sign)
return {'FINISHED'}

def register():
bpy.utils.register_class(SCREEN_OT_set_by_name)

def unregister():
bpy.utils.unregister_class(SCREEN_OT_set_by_name)

if __name__ == "__main__":
register()

# test call
bpy.ops.screen.set_by_name(name="Default")


Keymap F1 to change to "Default" screen.

• Thank you batFINGER, but I'm not very good with scripts and I'm not sure what to do with this code.I tried to paste it in the text editor but when I hit "Run Script" it says "Python script fail, look in the console for now..." – Chris Sep 17 '16 at 11:33
• Look in the console then, and post what the error message was. If you are on Windows OS just use Window > Toggle System Console. – JakeD Sep 17 '16 at 11:35
• Sorry it was a cut n paste error, missing import bpy. Edited answer. – batFINGER Sep 17 '16 at 11:57
• Thank you very much. That worked perfectly. There is only one small thing, if I press "F1, F2, F1", the screen layouts switch perfectly, but when I press consecutively "F1, F1", I get the error: Traceback (most recent call last): File"\Text.001", line 22, in execute ZeroDivisionError: division by zero location: <unknown loccation>:-1 Can this error message be removed? – Chris Sep 17 '16 at 12:36
• Fixed. Was sure I put that check in in the first place... Copy / Paste run again. – batFINGER Sep 17 '16 at 12:56