You would have to search the forum for examples.
As to how this works, build the macro first. Make it do the compact and repair without exiting. OK, add the QUIT command as the last element of the macro. Test that. (This is the aw-shucks part because Access will exit when you test it...)
OK, you are good for part 1.
Now part 2 - write a .BAT file that runs access from where it is installed, pointing to the database you want to do this to, with /X and the macro name.
Part 3 - In Windows task scheduler, have it run the .BAT file. Windows scheduler knows what to do with batch files when it sees that file type, so it won't be TOO stupid - i.e. more stupid than any Windows function ever is.
The task scheduler will do the scheduling part. (That almost sounds like a "Well, DUH" statement, doesn't it?) The batch job supplies the pointer to the database and the macro. And the macro does the compact, repair, and quit for you.
A DB does not need to know how it was opened. In this context, it should never WANT to know.