Skip to content

Instantly share code, notes, and snippets.

@keith
Last active December 10, 2015 05:58
Show Gist options
  • Select an option

  • Save keith/4390897 to your computer and use it in GitHub Desktop.

Select an option

Save keith/4390897 to your computer and use it in GitHub Desktop.
Global shortcut show hide window method
- (void)showHideMainWindow {
NSNumber *wasActive = @NO;
if ([[NSRunningApplication currentApplication] isActive]) {
wasActive = @YES;
NSNumber *wasOpen = @NO;
if ([self.window isVisible]) {
wasOpen = @YES;
[self.window close];
[[NSApplication sharedApplication] hide:self];
} else if (![wasOpen boolValue]) {
[self.window makeKeyAndOrderFront:self];
}
} else if (![wasActive boolValue]) {
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
[self.window makeKeyAndOrderFront:self];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment