Get Number of Screens Using system_profiler Using the system_profiler SPDisplaysDataType command in terminal will give info of all connected displays; something like this.

Graphics/Displays:

    NVIDIA GeForce GT 640M:

      ...

      Displays:
        iMac:
          ...
        DELL P2214H:
          ...
        DELL P2214H:
          ...


Is it possible to get the total number of connected displays, in this case 3? If not, then how can the above output be parsed to return the total connected displays.
This can be achieved by parsing the output of system_profiler SPDisplaysDataType with this line.

system_profiler SPDisplaysDataType | grep Resolution: | wc -l

As fd0 mentioned, this can be shortened to this.

system_profiler SPDisplaysDataType | grep -c Resolution