Oct 04, '05 06:06:00AM • Contributed by: Anonymous
- Open desired window in Finder
- Command-tab to Terminal
- Type a command to get me to aforementioned window
cdh() # cd's to frontmost window of Finder
{
cd "`osascript -e 'tell application "Finder"' \
-e 'set myname to POSIX path of (target of window 1 as alias)' \
-e 'end tell' 2>/dev/null`"
}
Close and reopen the Terminal, or type source .bashrc to activate the new command. From now on, you can just type cdh in Terminal, and automagically cd to the frontmost Finder window.
[robg adds: The code above is the result of an exchange between the author and I; it seems to work fine on both 10.3 and 10.4 machines, though I'm sure there may be better ways to achieve the same results. Note that I've broken the code onto multiple lines for a narrower display; it should work fine with a copy and paste, but if it breaks, remove the backslashes and line breaks from the cd "`... section, and make it one long line.]
