Last Updated: February 25, 2016
·
318
· furikuri

Change directory to current Finder's path

Put this little bash function in your .bash_profile and you can change to the directory of the current Finder's path. Just type cdf:

cdf() {
    target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
    if [ "$target" != "" ]; then
        cd "$target"; pwd
    else
        echo 'No Finder windows are opened' >&2
    fi
}