Sublime Forum

Events for application start/close

#1

Hello,

is there any way to execute code just before the application start closing or just after the application has been fully started (meaning that last workspace has been restored as well).

I’m trying to do some cleanup / bootstrap for my plugin (change window layouts and close temporary buffers that it uses), but so far I haven’t anything that would work as I described above. I was presuming that I could use an EventListener for that, but it only triggers to open/close events of views, not the application itself.

0 Likes

#2

I know I’m reviving an old animal here, but does anybody have any information on this? It’d be a really good idea to have a close hook with Sublime 3 (or 2) to be able to cleanup any servers you may’ve created

0 Likes

#3

i’m interested in that too, though I suppose it’s the kind of thing that’s built for an OS to do…
e.g. in windows a bat file could do something before it runs, run it, then do something after it runs. Or jscript/vbscript, a .js file or .vbs file, could launch sublime, and do something before and after(with no cmd window popping up). Bear in mind also that an application can be closed with tasklist /f /im blah.exe and it’s closed before it knows what hit it. So to really know it has just closed, the wrapper method provided by the OS, OS scripting, seems good.

0 Likes

#4

For open, you can probably use plugin_loaded with an ‘already loaded’ global variable.

Example:

def plugin_loaded():
    global loaded
    try:
        loaded
    except NameError:
        loaded = True
        do_startup_stuff()

For cleaning up subprocesses on close, you can fork a subprocess that monitors sublime. If the sublime process disappears, you can do cleanup. This isn’t super portable, but you can use third-party modules like psutil to help or check your platform and use ctypes on Windows.

0 Likes