Sublime Forum

Is there a way to run code on window close and/or shutdown?

#1

I need to make sure some processes are killed.

EDIT: Before anyone suggests atexit.register(), it doesn’t work. Nor does unload_handler(). :open_mouth:

0 Likes

#2

Surely someone has had to do this before. I’ve tried so many things and nothing works.

0 Likes

#3

I use the Hooks package. Install it, then you can add bindings in your user sublime-settings file.

The following runs the saveAll command right before a window is closed (not when the application is exited). It helps me from losing unsaved tabs if I close the window and there’s another window open.

"on_pre_close_window": [
	{
	"command": "saveAll",
	"scope": "window"
	}
]
0 Likes