Backport PR #4880: set profile name from profile_dir

in case profile_dir is set directly (e.g. in the notebook)

closes #4238