Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS X app that works without being active?

Tags:

macos

cocoa

Recently i've tried ColorSnapper app, and I've noticed that it works keeping other applications active.

(Check the screen below, as you can see safari window is still active and ColorSnapper keeps being active too).

enter image description here

How can is possible reproduce this effect ?

like image 985
MatterGoal Avatar asked May 11 '12 11:05

MatterGoal


3 Answers

I just try it and LSBackgroundOnly is the solution, but you must set the level of the window.

Example :

[mySpecialNSWindow setLevel:NSMainMenuWindowLevel];

This will display the special window above the windows of other applications.

like image 43
jackjr300 Avatar answered Sep 23 '22 06:09

jackjr300


I think the right approach is a mixture of (1) making the app LSBackgroundOnly, (2) using a custom transparent window as described here and set its level to NSFloatingWindowLevel, (3) using something like this in your app delegate to monitor mouse movements though your app is not active and, for example, to let your window follow the mouse position:

[NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask handler:^(NSEvent *event) {
        [window setFrameOrigin:[NSEvent mouseLocation]];
    }];

You can then have views as you like in the (transparent) window, move them around and modify its contents according to the mouse position.

like image 28
Tim Avatar answered Sep 23 '22 06:09

Tim


I believe these types of apps use LSBackgroundOnly or LSUIElement as Launch Services keys in their plist files (reference).

Here's a bit more about it.

like image 54
trojanfoe Avatar answered Sep 25 '22 06:09

trojanfoe