🛠️

LSUIElementとLSBackgroundOnlyの違いって何?

2021/05/16に公開

メニューバー常駐型アプリばかりを開発している筆者ですが、Info.plistに登録するキーであるLSUIElement(Application is agent (UIElement))とLSBackgroundOnly(Application is background only)の違いをあまり理解せずに使っていたので確認してみました。

公式のドキュメント[1]によると、
LSUIElement

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.

LSBackgroundOnly

LSBackgroundOnly (Boolean - macOS) specifies whether this app runs only in the background. If this key exists and is set to YES, Launch Services runs the app in the background only. You can use this key to create faceless background apps. You should also use this key if your app uses higher-level frameworks that connect to the window server, but are not intended to be visible to users. Background apps must be compiled as Mach-O executables. This option is not available for CFM apps.

となっており、LSUIElementの方はDockにアプリアイコンが表示されないようになり基本的にはバックグラウンドで動くが、必要に応じてフォアグラウンドでUIを表示することができるもの。LSBackgroundOnlyの方は完全にバックグラウンドでのみ動くもの。ということのようです。

ですので、メニューバー常駐型アプリの場合はLSUIElementをYESに設定すると良さそうです。
また、Helperアプリなど完全に表に出ないものはLSBackgroundOnlyを使うと良さそうです。

脚注
  1. Information Property List Key Reference ↩︎

Discussion