Catch quit blender event in addon
one way could be by running Blender from the terminal and just add &amp;&amp; at the end.
NB. not sure on windows though havent try it myself.

mac:

cd /Applications/Blender
./blender.app/Contents/MacOS/blender &amp;&amp; do_something


linux:

cd &lt;blender installation directory&gt;
./blender &amp;&amp; do_something


windows

cd c:\&lt;blender installation directory&gt;
blender -and do_something


on unix based system the &amp;&amp; command does something if the command before has successful, so basically in this case only after you quit blender it will run the second command. on windows -and should probably do the same.

you could also probably catch it by launching blender inside python using the subprocess module. But haven't try that yet.