Navigate to the next/previous page using only the black rectangle

I’m trying to write a script that would store the number of bars on each staff (system), then – after inserting empty bars somewhere in the middle of the piece – restore the bar number on each stave after the insertion point. My script would be a workaround to this unanswered post: