I want to build a simple service that will allow me to keep any app window always on top or always on the same screen, when switching desktops.

Is there a way to build a global MacOS service-only application (without any windows etc.) and how is the preferred way to do this? (Automator, AppKit, SwiftUI). The app should also be distributable via AppStore (or if not possible just GitHub).

  • 1
    You can have an app follow you to all Spaces by setting it in the Dock. I'm pretty sure that the 'float on top' aspect is not possible unless it's coded into the app itself. VLC can do that, as can Apple's own Picture in Picture. – Tetsujin Dec 28 '20 at 15:45

You could build such a service using any tool that results in an application bundle; this includes AppleScript/JavaScript (OSA), Objective-C, and Swift. Apple would likely prefer you used Swift.

Investigate the Accessibility APIs for interacting and manipulating windows owned by other applications.

See the Info.plist value LSUIElement for making an agent application:

LSUIElement (Boolean - macOS) specifies whether the app runs as an agent app. If this key is set to YES, Launch Services runs the app as an agent app. Agent apps do not appear in the Dock or in the Force Quit window. Although they typically run as background apps, they can come to the foreground to present a user interface if desired. A click on a window belonging to an agent app brings that app forward to handle events.

The Dock and loginwindow are two apps that run as agent apps.

To be distributed on Apple's Mac App Store, an application must have a user interface. This can be a simple window that enables your service, or handles preferences.

Search GitHub for status menu app for open source examples.

  • 1
    While your answer contains some good information, nonetheless, it doesn't really address "I want to build a simple service that will allow me to keep any app window always on top or always on the same screen, when switching desktops.". At one time there used to be a few third-party utilities that did this, however, due to security changes and sandboxing in macOS none of these work any more. I think creating an application/service that can do as expressed in the first sentence of the OP is not easily doable if at all, in recent version of macOS. – user3439894 Dec 28 '20 at 16:30
  • As asked, the question is too broad for me to answer with more certainty. True, the task is difficult. Probably too difficult to justify any monetary return. That aside, if granted accessibility rights, an application should be able to provide the behaviour being sought. – Graham Miln Dec 28 '20 at 17:48
  • I was thinking about doing it via Automator and JXA but the docs are quite awful and outdated … – uloco Dec 28 '20 at 19:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .