  Like most perovskites, SrRuO$_3$ exhibits structural phase transitions
associated with rotations of the RuO$_6$ octahedra. The application of moderate
magnetic fields in the ferromagnetically ordered state allows one to fully
control these structural distortions, although the ferromagnetic order occurs
at six times lower temperature than the structural distortion. Our neutron
diffraction and macroscopic measurements unambiguously show that magnetic
fields rearrange structural domains, and that for the field along a cubic
[110]$_c$ direction a fully detwinned crystal is obtained. Subsequent heating
above the Curie temperature causes a magnetic shape-memory effect, where the
initial structural domains recover.
