trying to automatize save a copy with "make local" for game engine

Hi! im using blenderfiles in gamekit/ogre game engine, and this doesnt support linked objects. So, now i manually click make local, save as a copy, and then undo the make local and save it again in the original file.

I want to do this in one easy script, but i have problems with undo command.


        bpy.ops.object.make_local(type='ALL')
        filepath = bpy.data.filepath        directory=os.path.dirname(filepath)
        bpy.ops.wm.save_as_mainfile(filepath=directory+"\copia.blend", copy=True)
        bpy.ops.ed.undo()

in this case, undo function reverse the make local, but also undoes any action done before this.

Another idea I had in mind to do this, is that the script creates a copy of the blender file, then open it, make changes, save and then return to the original file. Think of it this way, it would also be possible to access this script from the linked object file, without having to open the main blender file only to run the script.
But i dont know how to do this, and if is possible to start a script from one file, end in another , and then automatically go back to previous file.