cdff - cd to the path of the front-most Finder window

Terminal commands tocd to the front-most Finder window:

function ff { osascript -e 'tell application "Finder"'\
 -e "if (${1-1} <= (count Finder windows)) then"\
 -e "get POSIX path of (target of window ${1-1} as alias)"\
 -e 'else' -e 'get POSIX path of (desktop as alias)'\
 -e 'end if' -e 'end tell'; };\

function cdff { pushd "`ff $@`"; };

Bonus: copy the path of the frontmost finder window to the clipboard:

function pwdff { echo -ne "`ff $@`" | pbcopy; };

Source: Mac OS X Hints forum post


🌟 Was this page helpful? Please let me know with this quick, 3 question survey.