This only exports output cells, but does work.
SetOptions[EvaluationNotebook[], NotebookEventActions -> {
{"MenuCommand", "Save"} :>
Module[{loc, nb, new = FileNameJoin@Append[
Drop[FileNameSplit@NotebookFileName[], -1],
FileBaseName@FileNameTake[NotebookFileName[]] <> ".m"
]
},
NotebookSave[InputNotebook[]];
loc = FileNameJoin[{$TemporaryDirectory, "output.txt"}];
nb =
CreateDocument[NotebookGet[InputNotebook[]][[1]],
Visible -> False];
FrontEndExecute[FrontEndToken[nb, "Save", {loc, "Text"}]];
NotebookClose[nb];
DeleteFile[new];
CopyFile[loc, new];
]
}]