def force_close_view(view): view.set_scratch(True) win = view.window() win.focus_view(view) win.run_command('close')