This method seems to only work for the Close command, and the top menu File/Close option. I couldn't get it to work with the upper right [X] close pick method. Also I didn't include the CUI request. I'm not sure how to do it.
(command "._undefine" "close")
(defun c:Close ()
;Include all last commands before exit here.
(setvar "OSMODE" 7);endpoint, midpoint, center
;Purge layer A-Furn if nothing on it
(if (and (not (ssget "x" (list '(8 . "A-Furn"))))(tblsearch "LAYER" "A-Furn"))
(progn
(if (= (getvar "CLAYER") "A-Furn")
(setvar "CLAYER" "0");Your choice here
);if
(command "PURGE" "A-Furn" "N")
);progn
);if
(command "._qsave")
(command "._close")
);defun c:Close