Picture-entity card running script but which state depends on another entity state

Change the entity to media_player.whatever_your_tv_is and change the tap action to call-service and specify your script in the service data.

The name changing would require using custom Lovelace template card.