Created
November 6, 2009 09:58
-
-
Save tonyarnold/227877 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSApplication+DockIcon.m | |
// Hyperspaces | |
// | |
// Created by Tony Arnold on 30/06/09. | |
// Licensed under Creative Commons Attribution 2.5 - http://creativecommons.org/licenses/by/2.5/ | |
#import <Cocoa/Cocoa.h> | |
#import <Carbon/Carbon.h> | |
@interface NSApplication (DockIcon) | |
- (BOOL)showsDockIcon; | |
- (void)setShowsDockIcon:(BOOL)flag; | |
@end | |
@implementation NSApplication (DockIcon) | |
- (BOOL)showsDockIcon { | |
return [[NSUserDefaults standardUserDefaults] boolForKey:@"ShowDockIcon"]; | |
} | |
- (void)setShowsDockIcon:(BOOL)flag { | |
// this should be called from the application delegate's applicationDidFinishLaunching | |
// method or from some controller object's awakeFromNib method | |
// Neat dockless hack using Carbon from <a href="http://codesorcery.net/2008/02/06/feature-requests-versus-the-right-way-to-do-it" title="http://codesorcery.net/2008/02/06/feature-requests-versus-the-right-way-to-do-it">http://codesorcery.net/2008/02/06/feature-requests-versus-the-right-way-...</a> | |
if (flag) { | |
ProcessSerialNumber psn = { 0, kCurrentProcess }; | |
// display dock icon | |
TransformProcessType(&psn, kProcessTransformToForegroundApplication); | |
// enable menu bar | |
SetSystemUIMode(kUIModeNormal, 0); | |
// switch to Dock.app | |
[[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:@"com.apple.dock" options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:nil launchIdentifier:nil]; | |
// switch back | |
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment