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

Click here to return to the 'Control the Finder with the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Control the Finder with the Terminal
Authored by: NapoleonWils0n on Dec 13, '12 05:55:13PM

Heres a more accurate description
Changing directory in the Terminal changes the front most Finder window to the same directory

This isnt just opening a Finder window to the current Terminal directory like the open command
Or opening a Terminal window to the current Finder directory like go2shell

This code can do both of these and much more

When you cd in the Terminal to change directory the front most Finder automatically changes to the same directory

Ill try and explain how this code is different from the open command,
what it does and how it works

Heres how the open command works:

With the open command you can type: open Desktop in the terminal and this will open the Desktop in a new Finder window

If you already have a Finder window open, the open command will open the Desktop in a second Finder window

When you use the open command to open a directory in the Finder from the Terminal it will always open another Finder window, it doesnt change the directory of the front most Finder window.

eg if you type:

open Desktop
open Pictures
open Sites

You would end up with 3 Finder windows

Heres what the code does instead:

When you cd into a directory in the Terminal the front Finder window changes to the same directory, if a Finder window isnt open it will open one for you

The code works with .bash_completion and some options set in .inputrc like ignore-case

For example here's how you would change the front Finder window to your Music folder in ~/Music/iTunes/iTunes\ Media/Music/

cd m + tab 2 times
expands to: cd Music/

cd Music/i + tab once
expands to: cd Music/iTunes/

cd Music/iTunes/i + tab once
expands to: cd Music/iTunes/iTunes\ Media/

cd Music/iTunes/iTunes\ Media/m + tab 3 times
expands to: cd Music/iTunes/iTunes\ Media/Music/

You can then type: column, list or icon to change the Finder windows view

The CDPATH variable is set in the .bash_profile to the home directory, so you can cd back to any directory in your home quickly

If you type cd d + keep pressing tab it will cycle through all the directories begining with d
For example: Desktop, Documents, Downloads, Dropbox

You need to download and install bash_completion in /etc

[ Reply to This | # ]
Control the Finder with the Terminal
Authored by: dzurn on Dec 18, '12 10:29:18AM
I use ZSH, so your iTunes example would get reduced to this with the builtin zsh completions:

cd ~/M/i/i 
then hit {tab} and it expands to:
cd ~/Music/iTunes/iTunes\ Music/

Not to take anything away from your code, since I can see it being useful to have a Finder window "follow" the current directory. However there's times I use the Terminal to navigate to folders with thousands of files that otherwise woule take a looong time to show in the Finder.

Madness takes its toll.
Please have exact change.

[ Reply to This | # ]