  We propose a versatile and efficient method to generate a broad class of
complex entangled states of many atoms via the detection of a single photon.
For an atomic ensemble contained in a strongly coupled optical cavity
illuminated by weak single- or multi-frequency light, the atom-light
interaction entangles the frequency spectrum of a transmitted photon with the
collective spin of the atomic ensemble. Simple time-resolved detection of the
transmitted photon then projects the atomic ensemble into a desired pure
entangled state. This method can be implemented with existing technology,
yields high success probability per trials, and can generate complex entangled
states such as multicomponent Schr\"{o}dinger cat states with high fidelity.
