Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide terminal window in mac osx?

Tags:

c++

macos

I have a multi platform application that runs on Windows, Linux, Android and Mac. It is compiled with g++ on all platforms.

For windows, I created an installer and got rid of the terminal window by adding the linker flag:

-Wl,--subsystem,windows

I am looking for a similar option on Mac. How do I get rid of the console window when I open the executable from GUI?

This question is similar to How to hide console window in Mac OS (gcc compiler)?, except that my app is no daemon.

Thanks.

like image 533
Matferib Avatar asked May 26 '14 02:05

Matferib


People also ask

How do you hide a Terminal window on a Mac?

In the Terminal app on your Mac, do any of the following: Display the alternate screen: Choose View > Show Alternate Screen. Switch back to the main screen: Choose View > Hide Alternate Screen.

How do I get rid of the top window on my Mac?

On your Mac, do any of the following in an app: Hide or show the toolbar: Choose View > Hide Toolbar or View > Show Toolbar. While working in full screen for some apps, choose View > Always Show Toolbar in Full Screen.

How do you hide a screen on a Mac?

Selecting Automatically hide and show the Dock under System Preferences > Dock & Menu Bar does the trick. Also, check the box for Minimize windows into application icon to prevent individual app windows from cluttering up the dock. You can also control your Mac's Dock hiding with a shortcut (Option + Cmd + D).


1 Answers

Based on your description, you're building what is a unix-style executable. On OS X, those will always launch inside of a terminal window. The choices that you have on OS X are:

  • Run as a daemon as described in the above-linked post
  • Run in Terminal as a unix executable
  • Create a minimal OS X application wrapper and run as an OS X Application

In most cases, you can create a wrapper for a unix-style executable by creating the appropriate Bundle using the instructions from Apple's Bundle Programming Guide (skip over the iOS stuff and look at the Mac bundle information).

The basic directory structure is:

MyApp.app/
  Contents/
    Info.plist
  MacOS/
    executable
  Resources/
    MyApp.icns

Your unmodified executable can go in the MacOS directory, and you'll need to set up the following keys in the Info.plist using a plist editing tool or editor:

  • CFBundleIdentifier - the id of your app in reverse-dns notation (com.mycompany.myapp)
  • CFBundleDisplayName - the name of your app in human-readable form (MyApp)
  • CFBundleName - the short name of the app (usually the same as your app and executable name)
  • CFBundleVersion - your version # in X.Y[.Z] form
  • CFBundlePackageType - the package type, which should be APPL for applications
  • CFBundleExecutable - the name of your executable
  • CFBundleSignature - old-school Apple signature (4 character code that should theoretically be registered with apple)

A minimal plist would look like this: CFBundleDisplayName MyApp CFBundleExecutable a.out CFBundleIdentifier com.mycompany.myapp CFBundleName MyApp CFBundlePackageType APPL CFBundleSignature FOOZ CFBundleVersion 1.0

(The above example uses a.out as the executable, which would be located in MyApp.app/Contents/MacOS/a.out)

The icon resources can be left out if you don't care about the icon, and the default application icon will be used.

like image 154
gaige Avatar answered Oct 01 '22 20:10

gaige