Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Automatically cd to active Finder directory in new Terminal window' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically cd to active Finder directory in new Terminal window
Authored by: ioioi on Sep 23, '11 07:50:17PM
This is a poor method to use, since clicking on any other window in Finder prior to entering Terminal becomes the path, resulting in an error:
$ cdf
execution error: Can’t make «class fvtg» of window 1 of application "Finder" into type string. (-1700)
A more effective way is like this, which also displays the path:
# cdf: cd's to frontmost window of Finder
cdf () 
    currFolderPath=$( /usr/bin/osascript <<"    EOT"
        tell application "Finder"
                set currFolder to (folder of the front window as alias)
            on error
                set currFolder to (path to desktop folder as alias)
            end try
            POSIX path of currFolder
        end tell
    echo "cd to \"$currFolderPath\""
    cd "$currFolderPath"
resulting in:
$ cdf
cd to "/Users/ioioi/Documents/..."
orion:Documents ioioi$ 

[ Reply to This | # ]