Shortcut to execute a Macro or Script Is it possible to remap a key to call more than one operator at a time, or to execute a python script?    

In my workflow I need to use two operators, one after the other:
Set the 3D cursor to selection, followed by set origin to 3D cursor.  

I never use the 0 key to switch layers,so I thought it would be faster to make it "set origin to selection", but i don't know how to make it call those two in one go.
bpy.ops.view3d.snap_cursor_to_selected()
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')

If this works it would save me exactly 6 key presses:
Shift+S ,4, tab to go to object mode,Shiftctrlaltc,3,tab to go back to edit mode.

Thanks for any input

Edit : This works when executed from a text editor, now i just need to figure out a way to execute it with the 0 key.

import bpy

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        context = bpy.context.copy()
        context['area'] = area
        context['region'] = area.regions[-1]
        bpy.ops.view3d.snap_cursor_to_selected(context)
        bpy.ops.object.editmode_toggle()
        bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
        bpy.ops.object.editmode_toggle()
        break
Here's a quick example adapted from the ObjectCursorArray tutorial in the API documentation.

You should be able to run this in the text editor, and then pressing Numpad 0 in Object view should result in the "do work here" text printing to the console window (in OSX/Linux you have to launch Blender from the terminal to see the console output).

Note: once you copy this script into blender, you may want to check that the tab structure is still correct for each line.

bl_info = {
    "name": "Work Macro",
    "category": "Object",
}

import bpy


class WorkMacro(bpy.types.Operator):
    """Work Macro"""
    bl_idname = "object.work_macro"
    bl_label = "Work Macro"
    bl_options = {'REGISTER', 'UNDO'}


    def execute(self, context):

        print("do work here")

        return {'FINISHED'}


# store keymaps here to access after registration
addon_keymaps = []


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

    # handle the keymap
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
    kmi = km.keymap_items.new(WorkMacro.bl_idname, 'NUMPAD_0', 'PRESS', ctrl=False, shift=False)
    addon_keymaps.append(km)

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

    # handle the keymap
    wm = bpy.context.window_manager
    for km in addon_keymaps:
        wm.keyconfigs.addon.keymaps.remove(km)
    # clear the list
    del addon_keymaps[:]


if __name__ == "__main__":
    register()