I'm running the latest OS X (10.12.6) and something keeps annoying me **a lot** with spaces: if you have an external monitor plugged in and spend some time configuring/customising your spaces placement, when you unplug the monitor, everything is semi-randomized. Semi, because most of the spaces will stay in the same order, but the number of spaces and the location of the spaces will still change.

Here is what I have when the monitor is plugged in:

 * Monitor
   * space 1: empty
   * space 2: app
   * space 3: app
   * space 4: empty
 * mac book screen
   * space 5-10: app (1 per space)
   * space 11: empty

When I unplug the monitor, it becomes this:

* space 1: apps that was previously on space 5 and 6
* space 2-3: ok, same apps as before
* space 4-5: empty
* space 6: app that was previously on space 7
* space 7: app that was previously on space 8
* ^ repeat up to space 9 / previously space 10
* space 10: empty
* no more space 11


This is mostly annoying because I use keyboard shortcut to move between spaces, so basically I have a mental mapping of shortcut to app, but then it's all mixed up as soon as I unplug the monitor.

Is there a way to prevent this behaviour?