# MacServiceManagement

Import: `import com.install4j.api.macos.MacServiceManagement;`

```java
public class MacServiceManagement
```

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](https://developer.apple.com/documentation/servicemanagement/smappservice)

| Type | Kind | Description |
|---|---|---|
## Nested types

| [MacServiceManagement.AppServiceStatus](MacServiceManagement.AppServiceStatus.md) | enum | Enumeration representing the possible statuses of an application service or process. |
| [MacServiceManagement.ServiceManagementResult](MacServiceManagement.ServiceManagementResult.md) | enum | Result of a service management operation. |

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`registerMainBundleAsLoginItem()`](#registermainbundleasloginitem) | `ServiceManagementResult` | Registers the main bundle as a login item. |
| [`unregisterMainBundleAsLoginItem()`](#unregistermainbundleasloginitem) | `ServiceManagementResult` | Unregisters the main bundle as a login item. |
| [`getMainBundleLoginItemStatus()`](#getmainbundleloginitemstatus) | `AppServiceStatus` | Retrieves the status of the main bundle login item registration. |
| [`registerLaunchAgent(String)`](#registerlaunchagent-string) | `ServiceManagementResult` | Registers a launch agent specified by its property list (plist) file name. |
| [`unregisterLaunchAgent(String)`](#unregisterlaunchagent-string) | `ServiceManagementResult` | Unregisters a launch agent specified by its property list (plist) file name. |
| [`getLaunchAgentStatus(String)`](#getlaunchagentstatus-string) | `AppServiceStatus` | Retrieves the status of a launch agent specified by its property list (plist) file name. |
| [`registerLaunchDaemon(String)`](#registerlaunchdaemon-string) | `ServiceManagementResult` | Registers a launch daemon specified by its property list (plist) file name. |
| [`unregisterLaunchDaemon(String)`](#unregisterlaunchdaemon-string) | `ServiceManagementResult` | Unregisters a launch daemon specified by its property list (plist) file name. |
| [`getLaunchDaemonStatus(String)`](#getlaunchdaemonstatus-string) | `AppServiceStatus` | Retrieves the status of a launch daemon specified by its property list (plist) file name. |
| [`openSystemSettingsLoginItems()`](#opensystemsettingsloginitems) | `boolean` | Opens the system settings in the "Login Items" section, allowing the user to view or manage applications that are set to launch at login. |

### registerMainBundleAsLoginItem()

```java
public static ServiceManagementResult registerMainBundleAsLoginItem()
```

Registers the main bundle as a login item.


**Returns:** the result of the operation, represented as a [`ServiceManagementResult`](MacServiceManagement.ServiceManagementResult.md)

### unregisterMainBundleAsLoginItem()

```java
public static ServiceManagementResult unregisterMainBundleAsLoginItem()
```

Unregisters the main bundle as a login item.


**Returns:** the result of the operation, represented as a [`ServiceManagementResult`](MacServiceManagement.ServiceManagementResult.md)

### getMainBundleLoginItemStatus()

```java
public static AppServiceStatus getMainBundleLoginItemStatus()
```

Retrieves the status of the main bundle login item registration.


**Returns:** the status of the registration, represented as an [`AppServiceStatus`](MacServiceManagement.AppServiceStatus.md) enum value or `null` if the status could not be determined.

### registerLaunchAgent(String)

```java
public static 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 [`ServiceManagementResult`](MacServiceManagement.ServiceManagementResult.md)

### unregisterLaunchAgent(String)

```java
public static 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 [`ServiceManagementResult`](MacServiceManagement.ServiceManagementResult.md)

### getLaunchAgentStatus(String)

```java
public static 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 [`AppServiceStatus`](MacServiceManagement.AppServiceStatus.md) enum value or `null` if the status could not be determined.

### registerLaunchDaemon(String)

```java
public static 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 daemons 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 [`ServiceManagementResult`](MacServiceManagement.ServiceManagementResult.md)

### unregisterLaunchDaemon(String)

```java
public static 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 [`ServiceManagementResult`](MacServiceManagement.ServiceManagementResult.md)

### getLaunchDaemonStatus(String)

```java
public static 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 [`AppServiceStatus`](MacServiceManagement.AppServiceStatus.md) enum value or `null` if the status could not be determined.

### openSystemSettingsLoginItems()

```java
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.

## Constructors

| Signature | Description |
|---|---|
| [`MacServiceManagement()`](#macservicemanagement) |  |

### MacServiceManagement()

```java
public MacServiceManagement()
```

