Pages

Thursday, September 23, 2010

cd to the folder opened in Finder

Copy the following bash script and paste it in Terminal:
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 { cd "`ff $@`"; };
press Enter, then type cdff and press Enter. You will see that now the current folder in Terminal is the same as in the opened Finder.
You can save this function in .profile, re-open Terminal session and now, to switch to the folder opened in Finder, type 'cdff'.
Nice?
Don't tell me that you simply could drag an item from the Finder to the Terminal Window. :)
(If someone doesn't know, in Terminal type "cd ", then drag from the Finder Window the tiny icon near the folder name:

No comments:

Post a Comment