When a GUI process is launched from the OS X terminal, the window shows up in the background, and you have to use command-tab to give it focus.

Is there a way to make the terminal automatically give such GUIs focus after they are launched? For example (assuming gitk is installed):

% gitk

should launch the GUI and then switch to it.

Note: For several reasons, using open as this answer suggests is not a general solution.

Update: To better explain why the open method isn't satisfactory, here's a sample bash session (with witty commentary).

% cd /my_repo
% gitk

Waiting for the GUI to appear ... any day now ... oh wait -- it's already open. I just didn't notice because it opened a window BEHIND my terminal. I wonder how long I was going to sit here waiting....

% open gitk
The file /my_repo/gitk does not exist.

Ah, of course.

% which gitk
/usr/bin/gitk
% open /usr/bin/gitk

What the ... it opened a new terminal window to run gitk, and it did so in my home directory, not /my_repo, so gitk complains that the current directory isn't actually a repository...

Edit
Report