How to differentiate between Terminal scripted launch and manual launch for .bash_profile settings
You can display BASH variables on your .bash_profile. Then compare the output when you manually open the terminal with output when cd to app opens the terminal.

I meant append at the beginning of your .bash_profile the bash variables listed on the website:

echo $BASH
echo $BASHOPTS
echo $BASHPID
...
echo $TMPDIR
echo $UID


Then open manually the terminal and save the output.
Open the terminal from cd to and save the output.

Compare the files.



The proper variable for the above example is DIRSTACK.

Here are the new settings for those passing through:

# My settings
if [ $DIRSTACK = "~" ]; then
    trap 'printf %s "$PWD" &gt; ~/.storepwd' EXIT
    cd "$(&lt;~/.storepwd)"
fi