Automatically hide/disable second monitor's custom panels when second monitor is disabled?

Hey all,

My main computer runs a multi monitor setup where different combinations of monitors are active at different times depending on what I’m doing. I’m really enjoying the ability to set up custom panels that suit the purpose of each screen, but I’m hindered by the fact that when I turn an unused monitor off in the display settings the panels for that monitor are pulled onto my remaining active monitor(s).

I’d love to be able to set something up that either hides those panels or disables them entirely when their respective monitors are off, then restores them to their appropriate place when I turn that monitor back on. I haven’t seen any setting that will allow me to do that, but google has led me to believe I should be able to write a script that can do something like this.

I’m a moderately competent beginner with linux, but pretty new to the mate desktop environment and linux scripting in general. Can anyone point me to any relevant information/documentation I’d need to learn how to set up this kind of functionality?

After some googling I found a pretty straightforward way to do this, and it almost works perfectly.

Essentially I'm binding commands that switch between autorandr and mate-tweak profiles using xbindkeys, so when I hit a key combo it runs a command like:

autorandr --load [PROFILE] && wait && killall mate-panel && wait && mate-tweak --layout [MATE-PROFILE]

This works, with one major caveat. For some reason the panel applets on my secondary custom mate-tweak profiles are ridiculously glitchy and refuse to consistently load in when I switch to them.

My main custom panel profile consistently loads fine, as do all the defaults, but whenever I set up the panel for my secondary monitor applets either don't load or load twice. I haven't been able to pinpoint what's causing it, so I figured I'd ask if anyone knows what's going on. If needed I can submit a bug report if that's what's most appropriate.

After some more testing, I strongly suspect the bug resides in mate-tweak’s attempt to overwrite profiles with the same name. Looks like rather than deleting the previous profile and writing a new one with the same name, settings get mixed together and garbled.

This explains why not all profiles are affected, and after making a couple of new profiles with unique names the problem hasn’t surfaced.

Anyone care to test/confirm this on their own systems? [EDIT: I should probably specify that I’m running Ubuntu-MATE 18.04]