# PreLoginAgents

macOS supports the ability to run graphical applications pre-login:

> # [Running Agents Before Login](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CustomLogin.html#//apple_ref/doc/uid/10000172i-SW10-SW2)
>
> Most software that displays a user interface does not run prior to the user logging in. However, in some rare cases, it may be necessary to create a graphical agent that does.
> 
> By default, OS X does not allow any application to draw content prior to login. If you need to do so, your agent must call the [`setCanBecomeVisibleWithoutLogin:`](https://developer.apple.com/documentation/appkit/nswindow/1419179-canbecomevisiblewithoutlogin) method on its windows. For more information, see the documentation for that method and the [PreLoginAgents](https://developer.apple.com/library/archive/samplecode/PreLoginAgents/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004414) sample code.

The trick is to add the following lines to your launchd plist:

    <key>LimitLoadToSessionType</key>
    <string>LoginWindow</string>

We used this ability to show a notification window pre-login for [Power Manager](https://www.dssw.co.uk/powermanager) pending events.

This functionality may not be supported in the latest macOS; we have not relied on it for a long while.