No sound from Samsung TV Apps (Netflix, YouTube, etc)

Upon further research, I think I do need to connect an optical cable from the TV to the Receiver. However, I am still not sure how the receiver will know to switch from the cable box audio input (HDMI) to the TV audio input (optical) when I go from watching Cable to the Samsung Apps. Any thoughts?