Really, I thought TOS was pretty consistent about Scotty being 3rd in command. The rare times someone else was in the big chair could be put down to Scotty being off the ship on leave, or sick, or in a task that required his continuous attention (or IRL James Doohan being unavailable). You could also count the stripes.
If I had to guess who was 2nd officer in TOS I would definitely guess Scotty. But I'm really not sure based on what was actually shown if that Enterprise had any official 2nd officer at all, just like I'm really not sure if DS9 had one, either.