Class MacServiceManagement

java.lang.Object
com.install4j.api.macos.MacServiceManagement

public class MacServiceManagement extends Object
Methods for controlling helper executables that live inside an app’s main bundle on macOS.

This API is supported starting with macOS 13. Launch agents and daemons are only supported by single bundle archives and must be configured in the media wizard. The methods handling the main bundle can be used for all media types.

General info about these mechanisms can be found in the documentation of the Apple Service Management Framework

  • Constructor Details

    • MacServiceManagement

      public MacServiceManagement()
  • Method Details

    • registerMainBundleAsLoginItem

      public static MacServiceManagement.ServiceManagementResult registerMainBundleAsLoginItem()
      Registers the main bundle as a login item.
      Returns:
      the result of the operation, represented as a MacServiceManagement.ServiceManagementResult
    • unregisterMainBundleAsLoginItem

      public static MacServiceManagement.ServiceManagementResult unregisterMainBundleAsLoginItem()
      Unregisters the main bundle as a login item.
      Returns:
      the result of the operation, represented as a MacServiceManagement.ServiceManagementResult
    • getMainBundleLoginItemStatus

      public static MacServiceManagement.AppServiceStatus getMainBundleLoginItemStatus()
      Retrieves the status of the main bundle login item registration.
      Returns:
      the status of the registration, represented as an MacServiceManagement.AppServiceStatus enum value or null if the status could not be determined.
    • registerLaunchAgent

      public static MacServiceManagement.ServiceManagementResult registerLaunchAgent(String plistName)
      Registers a launch agent specified by its property list (plist) file name. The launch agent must be configured in the single bundle media wizard. The plist file is located inside the main bundle in Contents/Library/LaunchAgents.

      The launch agent is immediately bootstrapped and may begin running. In addition, launch agents registered with this method bootstrap on each subsequent login.

      Parameters:
      plistName - the name of the property list (.plist) file that defines the launch agent configuration.
      Returns:
      the result of the operation, represented as a MacServiceManagement.ServiceManagementResult
    • unregisterLaunchAgent

      public static MacServiceManagement.ServiceManagementResult unregisterLaunchAgent(String plistName)
      Unregisters a launch agent specified by its property list (plist) file name. The launch agent must be configured in the single bundle media wizard. The plist file is located inside the main bundle in Contents/Library/LaunchAgents.

      If the launch agent is currently running, it will be terminated.

      Parameters:
      plistName - the name of the property list (.plist) file that defines the launch agent configuration.
      Returns:
      the result of the operation, represented as a MacServiceManagement.ServiceManagementResult
    • getLaunchAgentStatus

      public static MacServiceManagement.AppServiceStatus getLaunchAgentStatus(String plistName)
      Retrieves the status of a launch agent specified by its property list (plist) file name. The plist file is expected to be located within the main bundle at Contents/Library/LaunchAgents.
      Parameters:
      plistName - the name of the property list (.plist) file that defines the launch agent configuration.
      Returns:
      the status of the launch agent, represented as an MacServiceManagement.AppServiceStatus enum value or null if the status could not be determined.
    • registerLaunchDaemon

      public static MacServiceManagement.ServiceManagementResult registerLaunchDaemon(String plistName)
      Registers a launch daemon specified by its property list (plist) file name. The launch daemon must be configured in the single bundle media wizard. The plist file is located inside the main bundle in Contents/Library/LaunchDaemons.

      The system won’t bootstrap the launch daemon until an admin approves the launch daemon in System Preferences. The system bootstraps launch daemon registered with this method and approved by an admin on each subsequent boot.

      Parameters:
      plistName - the name of the property list (.plist) file that defines the launch daemon configuration.
      Returns:
      the result of the operation, represented as a MacServiceManagement.ServiceManagementResult
    • unregisterLaunchDaemon

      public static MacServiceManagement.ServiceManagementResult unregisterLaunchDaemon(String plistName)
      Unregisters a launch daemon specified by its property list (plist) file name. The launch daemon must be configured in the single bundle media wizard. The plist file is located inside the main bundle in Contents/Library/LaunchDaemons.

      If the launch daemon is currently running, it will be terminated.

      Parameters:
      plistName - the name of the property list (.plist) file that defines the launch daemon configuration.
      Returns:
      the result of the operation, represented as a MacServiceManagement.ServiceManagementResult
    • getLaunchDaemonStatus

      public static MacServiceManagement.AppServiceStatus getLaunchDaemonStatus(String plistName)
      Retrieves the status of a launch daemon specified by its property list (plist) file name. The plist file is expected to be located within the main bundle at Contents/Library/LaunchDaemons.
      Parameters:
      plistName - the name of the property list (.plist) file that defines the launch daemon configuration.
      Returns:
      the status of the launch daemon, represented as an MacServiceManagement.AppServiceStatus enum value or null if the status could not be determined.
    • openSystemSettingsLoginItems

      public static boolean openSystemSettingsLoginItems()
      Opens the system settings in the "Login Items" section, allowing the user to view or manage applications that are set to launch at login.
      Returns:
      if opening the system settings is supported.