Jeff K. has a bone to pick with Apple:
I have a great set of speakers that I connected to my old iMac with a optical audio/mini-plug cable through the headphone jack. They had terrific sound. Imagine my surprise then when I connected the cable to the headphone jack on my new iMac and it wasn’t recognized. I called Apple, and it turns out someone decided to change that part of the audio electronics. No more digital optical. My speakers already have a DAC [digital-to-analog converter] built in, so it’s not a matter of adding one.
Starting in 2006, Apple incorporated support for S/PDIF, an optical digital connection standard that uses a fiber-optic cable with a Toslink connector or through Mini Toslink, which is compatible with standard 3.5mm audio jacks. This allowed higher-quality digital audio output, and this standard allows for 5.1 and 7.1 surround sound encoding, depending on the source device.
However, this support has disappeared in recent years, plausibly because it wasn’t being used by enough people to warrant its inclusion? We don’t know, and Apple doesn’t tell. The fourth-generation Apple TV was the first to lose it, and people were rather unhappy in 2015 when it happened. We published this guide to help folks work around the disappearance.
The 2016 and 2017 MacBook Pros and the 2017 iMacs omit S/PDIF from their headphone jacks, as Jeff discovered. To regain digital audio output, you have to purchase a USB-based device. While Jeff has speakers that handled the decoding, all the USB devices I’ve found include a DAC under the assumption that it’s required for the analog ports.

The USB-connected Behringer U-Control UCA202 has optical-digital output.
Of all the hardware out there, only the Behringer U-Control UCA202 states explicitly that it works on a Mac without requiring drivers. Reviewers at Amazon seem to agree. At $30 street, it’s not a bad add-on if you really want and need digital audio output.
Ask Mac 911
We’ve compiled a list of the questions we get asked most frequently along with answers and links to columns: read our super FAQ to see if your question is covered. If not, we’re always looking for new problems to solve! Email yours to mac911@macworld.com including screen captures as appropriate. Mac 911 can’t reply to—nor publish an answer to—every question, and we don’t provide direct troubleshooting advice.