As far as I remember, the story I'm looking for was published in a kids' activity book that featured puzzles, games, mazes and also a few short stories.
The book was bought in Switzerland about 20 years ago. The story was in German, I don't know whether it was translated from a different language.
The story is about a boy, maybe 10 years old, who has a shadow that gets him into (harmless) trouble. Makes him do mischief and gets him to have fun, like maybe take snacks without permission, of that sort.
He gets scolded for these activities and decides to get rid of his shadow. I don't remember how he manages to do this, but he locks his shadow in a cupboard or a shed.
He becomes docile and obedient and his life becomes boring. He then begins to get into real trouble - maybe cigarettes or hanging out with the wrong crowd? - and realizes that he needs to free his shadow to regain himself.
I don't remember much else of the story, but the last sentence was something like "playing in the boughs of a tree, with the white and the black keys of the piano".
"...spielten Klavier in den Ästen eines Baumes, mit den schwarzen und weißen Tasten."