code.google.com · Saved

detectdisplays - A command-line tool for Macs that detects attached displays. - Google Project Hosting

code.google.com/p/detectdisplays

From the page

Saved with the link. Notes from 2007 to 2016 are mostly the page's own words, so this is probably an excerpt.

Sometimes on a Mac, not all attached displays are immediately detected (such as if you open the lid on a MacBook Pro while attached to an external monitor or if you boot a Mac on a KVM while it isn't the active device). This tool has the same effect as clicking "Detect Displays" in the "Displays" System Preferences pane, making it suitable for a LaunchAgent to detect displays at login.