Hi - you can set the monitors dynamically like this:
local main_monitor = hs.screen.allScreens()[1]:name()
local second_monitor = hs.screen.allScreens()[2]:name()
... although I am not sure if that causes any trouble versus your current manual method.