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

Free scripts to improve UNIX/Finder interaction UNIX
Have you ever wanted to open a Terminal (or iTerm) immediately into the same directory displayed in the OS X Finder window?  You can do this and much more using Gary Kerbaugh's collection of UNIX utilities and Applescripts. Three shell scripts allow greatly increased synergy between the Finder and the command line. These can be supplemented with AppleScript applications that allow you, in one click, to open a Terminal window or iTerm tab in the directory corresponding to that shown in the finder.

These unix utilities include cdf, posd, fdc and rmm.

cdf and posd:
posd is an osascript embedded in a shell script that returns the directory corresponding to the frontmost Finder window.  Its real value is when aliased to the command cdf, i.e.:
 % cdf='cd "$(/sw/bin/posd)"'
The command cdf changes the terminal working directory to match that of the frontmost Finder window.

fdc:
fdc is essentially the reciprocal operation of cdf.  It changes the Finder window to match the current directory of the Terminal in which the command is issued.

rmm:
rmm is a shell script (also written by Gary; info/download) that emulates the GNU rm function, except that it moves files to the user's Trash directory, instead of unlinking them.   If you alias rm to rmm for your interactive sessions (only), then it can become a rm replacement that puts everything in the Trash can, much like Finder's delete.

I've put further details, including links to Finder toolbar applications, downloads, screenshots, fink ports and a few of my modifications on my website...
    •    
  • Currently 2.40 / 5
  You rated: 2 / 5 (5 votes cast)
 
[13,991 views]  

Free scripts to improve UNIX/Finder interaction | 12 comments | Create New Account
Click here to return to the 'Free scripts to improve UNIX/Finder interaction' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Free scripts to improve UNIX/Finder interaction
Authored by: jperkins on Sep 22, '03 11:09:12AM

These scripts can be found at:

<http://www.chemistry.ucsc.edu/~wgscott/xtal/terminal_finder_interactions.html>

An excellent find, btw!



[ Reply to This | # ]
Free scripts to improve UNIX/Finder interaction
Authored by: jperkins on Sep 22, '03 11:10:37AM

My apologies - I'd missed the second url in your hint. Still an excellent find!



[ Reply to This | # ]
Free scripts to improve UNIX/Finder interaction
Authored by: andrewz on Sep 22, '03 11:31:10AM
I've installed posd and fdc in /usr/bin, and they both work fine by themselves.

However, cd "$(/usr/bin/posd)" doesn't seem to work in my shell (I'm using tcsh). I just get an error saying "Illegal variable name."

Is there a different syntax that I need to use with tcsh to cd to the directory returned by running the posd command?

[ Reply to This | # ]

Free scripts to improve UNIX/Finder interaction
Authored by: lee1 on Sep 22, '03 12:30:53PM
I've been using the bash shell for so long that I'm not sure about my csh syntax, but I think this should work: First, put the new commands someplace conventional in your path, like /usr/local/bin. I think in csh type shells (such as tcsh) you need to type rehash now. Now you can just type the commands with no path. The alias you can define this way: alias cdf "cd `posd`" where those are backticks around the posd. That should be one way to do it.

[ Reply to This | # ]
Free scripts to improve UNIX/Finder interaction
Authored by: sreeves on Sep 22, '03 02:54:18PM

Backticks alone will not work because they will be evaluated when the alias is defined, not in the current context of the shell. You can see this by looking at the output from alias cdf. It will say "cd somedirectory".

You need to use the eval command, like this:

alias cdf 'cd "`eval posd`"'



[ Reply to This | # ]
Free scripts to improve UNIX/Finder interaction
Authored by: lee1 on Sep 23, '03 09:04:54AM

Right- I should have used single quotes, which does work (I just tested it in csh):

alias cdf 'cd `posd`'



[ Reply to This | # ]
Free scripts to improve UNIX/Finder interaction
Authored by: gatorparrots on Sep 22, '03 12:35:55PM
In c-shells (csh, tcsh), you want to use backticks (`) instead of the $() form. In this case, you would use:
cd "`/usr/bin/posd`"

$(somecommand) is newer Bourne-style syntax supported by bash, ksh, zsh, etc. The advantage of using that syntax is that it is nestable.

[ Reply to This | # ]

fdc
Authored by: sveinbjorn on Sep 22, '03 02:14:02PM
Hmm....cool stuff but fdc is kind of redundant. You can just type:

open .

to get a Finder window with the current working directory.



[ Reply to This | # ]
fdc
Authored by: wgscott on Sep 22, '03 03:04:25PM

The difference is it changes the current finder window. open . opens up a new one.

For me, cdf and its implementation as an iTerm applescript was the best part.

There are also two contextual menu additions, open Terminal and open iTerm that are functionally very similar. I like these a lot but for some reason they sometimes crash the finder...



[ Reply to This | # ]
fdc
Authored by: wgscott on Sep 22, '03 03:43:18PM

The difference is it changes the current finder window. open . opens up a new one.

For me, cdf and its implementation as an iTerm applescript was the best part.

There are also two contextual menu additions, open Terminal and open iTerm that are functionally very similar. I like these a lot but for some reason they sometimes crash the finder...



[ Reply to This | # ]
Free scripts to improve UNIX/Finder interaction
Authored by: kmue on Sep 23, '03 03:35:06AM
Could you please tell me where to download the rmm tool? The link you provided does not work... tia

[ Reply to This | # ]
Free scripts to improve UNIX/Finder interaction
Authored by: wgscott on Oct 16, '03 01:42:25AM

http://www.cs.ecu.edu/%7Ecollins/rm/rm.html



[ Reply to This | # ]