Class MacServiceManagement
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration representing the possible statuses of an application service or process.static enumResult of a service management operation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetLaunchAgentStatus(String plistName) Retrieves the status of a launch agent specified by its property list (plist) file name.getLaunchDaemonStatus(String plistName) Retrieves the status of a launch daemon specified by its property list (plist) file name.Retrieves the status of the main bundle login item registration.static booleanOpens the system settings in the "Login Items" section, allowing the user to view or manage applications that are set to launch at login.registerLaunchAgent(String plistName) Registers a launch agent specified by its property list (plist) file name.registerLaunchDaemon(String plistName) Registers a launch daemon specified by its property list (plist) file name.Registers the main bundle as a login item.unregisterLaunchAgent(String plistName) Unregisters a launch agent specified by its property list (plist) file name.unregisterLaunchDaemon(String plistName) Unregisters a launch daemon specified by its property list (plist) file name.Unregisters the main bundle as a login item.
-
Constructor Details
-
MacServiceManagement
public MacServiceManagement()
-
-
Method Details
-
registerMainBundleAsLoginItem
Registers the main bundle as a login item.- Returns:
- the result of the operation, represented as a
MacServiceManagement.ServiceManagementResult
-
unregisterMainBundleAsLoginItem
Unregisters the main bundle as a login item.- Returns:
- the result of the operation, represented as a
MacServiceManagement.ServiceManagementResult
-
getMainBundleLoginItemStatus
Retrieves the status of the main bundle login item registration.- Returns:
- the status of the registration, represented as an
MacServiceManagement.AppServiceStatusenum value ornullif the status could not be determined.
-
registerLaunchAgent
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 inContents/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
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 inContents/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
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 atContents/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.AppServiceStatusenum value ornullif the status could not be determined.
-
registerLaunchDaemon
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 inContents/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
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 inContents/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
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 atContents/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.AppServiceStatusenum value ornullif 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.
-