One line if-else statement should look like this:
[execution] if [condition] [else] [execution 2]
if statement:
[execution] if [condition] [else] None
if bpy.context.object.mode == "EDIT":
saved_location = bpy.context.scene.cursor.location.copy()
bpy.ops.view3d.snap_cursor_to_selected()
bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
bpy.context.scene.cursor.location = saved_location
bpy.ops.object.mode_set(mode="EDIT")
if bpy.context.object.mode == "OBJECT":
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
This code is too long for one-liner code (hard to read) but do-able. Note that you can use only 1024 chars in PME one-liners. Here is the code:
{locals().update(saved_location=bpy.context.scene.cursor.location.copy()), bpy.ops.view3d.snap_cursor_to_selected(), bpy.ops.object.mode_set(mode="OBJECT"), bpy.ops.object.origin_set(type='ORIGIN_CURSOR'), setattr(bpy.context.scene.cursor, "location", saved_location), bpy.ops.object.mode_set(mode="EDIT")} if bpy.context.object.mode == "EDIT" else None; bpy.ops.object.origin_set(type='ORIGIN_CURSOR') if bpy.context.object.mode == "OBJECT" else None
Still it’s better to use external scripts for multi-line code.