The macbook is used in the office. So I do not want to make it sound in the speaker. It should output sound when there is an earphone connected to it. Otherwise no sound.
Is it possible to configure in such a way?
Your Mac remembers loudness settings for each device individually. This means you can do the following:
These settings should actually be remembered, even when rebooting your Mac.