I think a shell in a terminal in Dolphin will see /proc/$PPID/exe as a symlink to /usr/bin/dolphin or so. Instead of xdotool, use realpath /proc/$PPID/exe and build your logic on the result.
$PPID is the process ID of the parent of the shell, set when the shell initializes.