Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X: Bring (non-bundle) GUI applications to foreground when launched from the command line

Tags:

terminal

macos

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...

like image 347
Stuart Berg Avatar asked Jun 28 '12 15:06

Stuart Berg


People also ask

Does Mac OS X have a GUI?

In Mac OS X, the graphical user interface (GUI) is based on the Aqua theme, menu bar, and iOS-like features.

Is Macintosh GUI or command line?

Key Points. macOS has a graphical user interface (GUI) that includes the Finder, designed to easily access files and perform tasks on a Mac. The command-line interface (CLI) is a powerful tool for performing advanced tasks as an IT administrator.

How do you use Mac command line?

In the Terminal app on your Mac, press the Up Arrow key. The last command you entered appears on the command line. Continue pressing the Up Arrow key until you see the command you want, then press Return.


1 Answers

Do you need to invoke it synchronously? If not, you could start it asynchronously with & and then activate it with osascript -e 'tell application "gitk" to activate'.

like image 93
Chris Page Avatar answered Sep 28 '22 16:09

Chris Page