Hide (but not quit) an app programmatically on OS X

Is there an option in OS X (JDK8u40) to programmatically hide the application, similar to what is usually achieved by the user who presses Cmd-H?

I tried, unsuccessfully:

  • the call to Stage.setIconified
  • a call to Stage.hide () with the Platform.setImplicitExit parameter previously set to true (=> the application remains active although the stage disappears)
  • call Stage.hide () without Platform.setImplicitExit option (=> application finished)
  • using AWT Robot to send a shortcut Cmd-H (the About box appears instead).
+3


source to share


1 answer


You can do this on OS X, for example, using the built-in Cocoa bindings for Eclipse SWT. This may not be the most elegant solution, but it should work. If you include the following dependency in your project (make sure -XstartOnFirstThread is disabled in your startup config)

<dependency>
  <groupId>org.eclipse.swt.org.eclipse.swt.cocoa.macosx.x86_64.4.3.swt</groupId>
  <artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
  <version>4.3</version>
</dependency>

      

you may call



OS.objc_msgSend(NSApplication.sharedApplication().id,
                    OS.sel_hide_);

      

This will call the same routine as CMD-h and thus only work with OS X.

0


source







All Articles