Title says it all. I just want to know what command to enter to change the working directory to the directory of whatever is open in the front finder window.
My answer is based off an answer to a similar question about how to get the path of the front-most window in Objective-C and Cocoa (which is apparently from a Mac OS X Hints tip which might have been your exact question). I've tested the command and it will work directory paths containing spaces too.
cd "`osascript -e 'tell application "Finder" to POSIX path of (target of window 1 as alias)'`"
Using bash? Add this function to your bash profile.
cdf () {
finderPath=`osascript -e 'tell application "Finder"
try
set currentFolder to (folder of the front window as alias)
on error
set currentFolder to (path to desktop folder as alias)
end try
POSIX path of currentFolder
end tell'`;
cd "$finderPath"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With