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


Click here to return to the 'Create a command to 'cd' to frontmost Finder window' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a command to 'cd' to frontmost Finder window
Authored by: Blah on Oct 07, '05 11:25:16PM

Sa-weeet!

Very nice job. As a long-time Mac developer, I've only recently started to take advantage of using the Finder's toolbar area for scripts (and can't understand why it's taken me this long to give it a try). As far as this script goes, I guess one might want to open a -new- terminal session at times, but then again, not always. Just thinking out loud....

In any case, this is a keeper, thanks.



[ Reply to This | # ]
Create a command to 'cd' to frontmost Finder window
Authored by: szedula on Oct 08, '05 05:13:24AM

If you'd prefer that as the default response, you can easily get that by changing the "false" argument in calls to "CD_to" to "true".



[ Reply to This | # ]
Create a command to 'cd' to frontmost Finder window
Authored by: suarez on Oct 09, '05 11:26:30AM
One problem with using osascript -e is that it's a tiny bit slow. I know, most people won't notice the speed difference, especially when you see the timing results below. What I use instead is:
tell application "Finder"
   try
      POSIX path of (target of window 1 as alias)
   on error
      POSIX path of (path to desktop folder as alias)
   end try
end tell
and save that as a script in my ~/bin folder. Then, in my .bashrc file, I alias cdf to use the script with:
alias cdf='cd "`osascript ~/bin/cdf.scpt`"'
(That's back-tick, double-quote, and single-quote, from inside to out.) Rather than have the 2>/dev/null code ignore the error message, I prefer to go to the desktop if there's no open Finder window. I tried the original solution, and it ran a little slower (by a mean of 85 ms over 10 trials) than this one. I thought I had noticed a little difference, so that's why I timed it.
This, combined with the TerminalHere contextual menu, satisfies my wish-list. There's another AppleScript floating around that does the opposite of this -- opens the current folder in Finder, but this works just fine for me and it's fast:
$ open .


[ Reply to This | # ]