Running Dockless

While working on feature requests for DateLine recently, I needed to add the ability to run the app Dockless - that is, without a menu bar or Dock icon.

In 10.5 and later, you can simply add the following key to your info.plist file to let LaunchServices know that you want your app to run Dockless:

<key>LSUIElement</key>
<true/>

But what if you want to be able to control in a preference item whether you app is Dockless or not?

It turns out that there is no Cocoa way to do this and some Carbon code is necessary. After a bit of Google Fu, I found this handy article at codesorcery. Thanks go to Justin for posing the question and to Dan who provided the actual code.

The problem with the above article, though, is that the definitive solution is only posted in the comments. So in the interests of making it easier to get your app running Dockless, I have tidied it up into a method snippet and posted it below.

- (void) setDockStatus {
        // 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 ([[NSUserDefaults standardUserDefaults] boolForKey:@"doShowInDock"]) {
		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:TRUE];
	}
}
 

Providing menus for dockless apps

I've used the open-source utility StepMenus for years to enable torn-off main menus for apps running Dockless. It's an oldie, but a goodie. I recently recompiled it for 64-bit SL, so it can run in System Prefs without needing a relaunch of the app.

Submitted by Leland (not verified) on Tue, 02/23/2010 - 06:10.
but..what about menu?

Hello.

I have the following problem.
I want to have app that is without dock icon but if you open the UI from tray status icon an application menu appears.
Now it seems that presense of Dock icon and App's Menu is tied together and the question is if there is a real way to make this happen: Have app without dock icon as agent but have App's menu visible while MainWindow got focus.

regards

Submitted by zden (not verified) on Wed, 01/20/2010 - 08:35.
Re: but..what about menu?

Hi zden,

As far as I am aware, there is no way to have a dockless app with a menu.

Regards,

Alex

Submitted by alex on Wed, 01/20/2010 - 09:04.
Hide dock but show status menu bar

Hi, Alex,

I think zden means the status bar menu. Actually, I have the same question. Without dock icon, how to make an application frontmost? You can not use command+tab to switch between applications(seems that only running application with docked icon will show in the switch list). But you can use Expose's All Windows to find your dockless application(by default, you just need to move your mouse to the right bottom corner of screen).

My try is: when dock is hidden, click a menu item in the status bar menu and invoke some method to make your main window topmost, but this does not work.
[yourMainWindow makeKeyAndOrderFront:sender];

I know one example with status bar menu and dock both configurable: CoverSutra. The show/hide dock and show/hide menu bar works well there.

So, if anybody has some idea, please tell me. Thanks.

Submitted by cool8jay (not verified) on Sat, 05/29/2010 - 03:18.
Re: Hide dock but show status menu bar

Hi,

[[NSApplication sharedApplication] activateIgnoringOtherApps:TRUE];

... may be what you are looking for.

Cheers,

Alex

Submitted by alex on Thu, 06/17/2010 - 07:00.
10.6

You can just add the following key to info.plist in 10.6 and your app will run without a dock icon and menu.
"Application is agent (UIElement)" to YES

Submitted by Lene (not verified) on Sun, 11/08/2009 - 17:38.
Re: 10.6

Hi,

I have updated this article to make it clearer that this is exactly the technique I am using, without having to read the referenced article on codesorcery.

Cheers

Alex

Submitted by alex on Fri, 12/04/2009 - 07:47.

Post new comment

The content of this field is kept private and will not be shown publicly.
Enter the code shown in the image:

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
17 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Donate!





If you like what you find here and wish to support further development of this site, please donate via PayPal. No account required.

Syndicate

Syndicate content

User login

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
7 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
Enter the code shown in the image: