Before you unplug the monitor, close everything that's not entirely on the main monitor. Applications generally save their state (including window placement) when they close, and read it when they open, so if the second monitor is present at both of those times you should be fine.
You can take advantage of applications which allow more than one instance to be open at a time, but only save state on close. Close the multi-monitor instance (which causes the state to be saved). Unplug the second monitor. If you have a second instance running, it should be repositioned onto the main monitor, or you can start another instance. Don't close this instance before plugging the second monitor in again and starting another instance (which would then read the multi-monitor configuration on startup). Then you can quit the single-monitor instance (saving that state), and then the multi-monitor instance (overwriting the single-monitor state).
A more complex option might include figuring out where the state is saved, backing it up, and writing a batch file / script to restore it before opening the application, which would allow you to make a link to do this automatically when you start the application.
Finally, there may be such a utility for your platform, or writing one might not be too complex. For Windows, there is a program called ShiftWindow that can reposition windows either on application startup or on a certain hot-key. I'm afraid I don't know MacOS well enough to say if a similar utility exists. This is probably the ideal solution, second only to having the OS support such a thing directly.