The best I have been able to figure out is:
func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if !flag{
In case you are looking for a cocoa-based solution for non-document apps. This is the equivalent of Adam's second solution.
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
{
if(!flag)
{
for(id const window in theApplication.windows)
{
[window makeKeyAndOrderFront:self];
}
}
return YES;
}
Swift 3: In AppDelegate.swift add a variable of type NSWindow
lazy var windows = NSWindow()
and implement applicationShouldHandleReopen:
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if !flag {
for window in sender.windows {
window.makeKeyAndOrderFront(self)
}
}
return true
}
Or using forEach:
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if !flag {
sender.windows.forEach { $0.makeKeyAndOrderFront(self) }
}
return true
}