Skip to main content

Reboot Pending Prompt - Detection [Macintosh]

Overview

This script serves as the detection logic for the "Reboot Pending Prompt" solution on macOS. Its primary function is to intelligently decide whether a reboot prompt should be displayed to the user.

It performs checks in three key areas:

  1. Operational Safety & Opt-In: Before evaluating necessity, the script checks the client-level opt-in status (cPVAL Reboot Prompt For MAC) and the device-level manual override (cPVAL Pending Reboot). It also checks if the OmniPrompt utility is already running to prevent conflicting actions.
  2. Necessity: It determines if a reboot is actually required by comparing system uptime against a configured threshold, or by checking for a manual administrator override. (Note: macOS does not have a Windows-style Registry pending reboot flag, so this specific trigger is omitted).
  3. Timing & Convenience: If a reboot is needed, the script validates if the current moment is appropriate for a prompt. It checks constraints such as "Quiet Hours" (suppress windows), weekend exclusions, user presence (logged in vs. lock screen), and ensures the user isn't prompted too frequently.

If the script determines a reboot is needed, the timing is valid, and no conflicting prompts are active, it returns an exit code that triggers the remediation (Autofix) script.

Install-In-Progress Protection

Before allowing any unattended reboot (no user logged in, or locked screen with the missed prompt threshold reached), the script checks whether software or updates are currently being installed. If an install is detected, the script exits cleanly without rebooting. It will try again on the next cycle after the install finishes.

This prevents the machine from restarting in the middle of a macOS software update, application installer, or feature upgrade.

The script looks for the following macOS-specific processes:

| Signal | What It Means | | :--- | | softwareupdate | macOS Software Update is actively installing an update | | install | A general macOS installer package is running | | msud | macOS Software Update Daemon is active | | setupd | macOS Setup Assistant or installer is running | | osinstallersetupd | macOS OS Installer is actively performing an upgrade |

Note: This check only applies to unattended reboots. If a user is at their desk and clicks "Yes" to reboot, the reboot happens immediately regardless of background installs. The user made a conscious choice to restart.

Platform Differences (macOS vs. Windows)

Administrators managing both platforms should be aware of the following behavioral differences in the macOS detection script:

  • No Registry Pending Reboot Check: macOS does not have a direct equivalent to the Windows CBS/Windows Update Registry keys. Reboot necessity is determined solely by the manual cPVAL Pending Reboot checkbox and the cPVAL Reboot Prompt Uptime Days threshold.
  • No Session 0 Isolation Workaround: On Windows, the script must check for a Scheduled Task to avoid conflicting with the Autofix script. On macOS, running as root from NinjaRMM already renders in the console user's session, so the script simply checks for a running OmniPrompt process (pgrep -x OmniPrompt) to avoid conflicts.
  • Different Install Signals: The Install-In-Progress guard checks for macOS-specific processes rather than Windows servicing processes or the MSI mutex.

Sample Run

Note: This script is specifically engineered to operate as the detection condition within the Reboot Pending Prompt - Macintosh compound condition. Manual execution is not recommended, as the script's output is intended to trigger automated remediation actions rather than provide direct feedback.

Dependencies

Custom Fields

Custom FieldTypeExampleScopeAvailable OptionsEditableDescription
cPVAL Reboot Prompt For MACDropdownEnableOrganization, Location, DeviceEnable, DisableYesCLIENT-level master switch. Enable = opted in client-wide; Disable = opted out; unset = defers to the per-device cPVAL Pending Reboot.
cPVAL Pending RebootCheckboxTrueDeviceTrue, FalseYesManual override to force a prompt cycle, and also opts this single machine in when the MAC-level switch is unset.
cPVAL Last PromptedText2024-05-20 14:30:00DeviceN/ANoTimestamp of the last successful prompt. Managed automatically by the script.
cPVAL Times PromptedNumeric2DeviceN/ANoCounter for how many times the user has been prompted. Managed automatically by the script.
cPVAL Reboot Prompt Uptime DaysNumeric14Organization, Location, DeviceN/AYesUptime threshold (days) to trigger a reboot. Set to 0 to disable.
cPVAL Reboot Prompt CountNumeric4Organization, Location, DeviceN/AYesMax number of prompts allowed before the cycle resets.
cPVAL Reboot Prompt Duration Between PromptNumeric4Organization, Location, DeviceN/AYesMinimum hours to wait between prompts.
cPVAL Reboot Prompt Skip WeekendsDropdownEnableOrganization, Location, DeviceEnable, DisableYesEnable to suppress prompts on Saturdays and Sundays.
cPVAL Reboot Prompt Suppress Time WindowText1800-0800Organization, Location, DeviceN/AYes24h time range (HHmm-HHmm) to suppress prompts.
cPVAL Reboot if Not Logged InDropdownEnableOrganization, Location, DeviceEnable, DisableYesEnable to reboot immediately if no user is signed in.
cPVAL Reboot During Suppress PeriodDropdownEnableOrganization, Location, DeviceEnable, DisableYesEnable to allow unattended/forced reboots during suppress windows or weekends.
cPVAL Max Missed Prompts Before ForceNumeric3Organization, Location, DeviceN/AYesNumber of consecutive missed prompts before forcing a reboot. Set to 0 to disable.
cPVAL Consecutive Missed PromptsNumeric2DeviceN/ANoNumber of consecutive times the prompt was skipped. Managed automatically.
cPVAL First Missed Prompt TimeText2024-05-20 14:30:00DeviceN/ANoTimestamp of the first missed prompt in the current streak. Managed automatically.

Configuration Hierarchy

The solution evaluates settings using a strict top-down hierarchy. If a value is configured at a higher priority level, it overrides the lower levels.

PriorityLevelDescription
1 (Highest)Device Level Custom FieldOverrides all lower levels. Applied to a specific endpoint.
2Location Level Custom FieldOverrides Organization level. Applied to all endpoints in a location.
3Organization Level Custom FieldGlobal default for the entire tenant.
4 (Lowest)Script Runtime VariableUltimate fallback default used if the custom field is blank at all levels.

Script Variables

Instead of hardcoding defaults, the script relies on NinjaRMM Script Variables as the ultimate fallback mechanism. You can configure these variables directly in the script's settings within NinjaRMM to establish global baseline behaviors without modifying the script file.

NameTypeExampleDefaultAvailable OptionsDescription
Prompt CountInteger54N/AMax number of prompts allowed before the cycle resets.
Duration Between PromptsInteger64N/AMinimum hours to wait between prompts.
Suppress Time WindowString/Text1800-0800(blank)N/A24h time range (HHmm-HHmm) to suppress prompts.
Max Missed Prompts Before ForceInteger30N/ANumber of consecutive missed prompts before forcing a reboot. Set to 0 to disable.
Reboot If Not Logged InDropdownEnableDisableDisable, EnableEnable to reboot immediately if no user is signed in.
Skip WeekendsDropdownEnableDisableDisable, EnableEnable to suppress prompts on Sat/Sun.
Reboot During Suppress PeriodDropdownEnableDisableDisable, EnableFallback default. Allows unattended/forced reboots during suppress windows.

💡 Note: Do not attempt to change default values by editing the script file directly. Modifying the script may break its execution or signature. Always use Custom Fields or Script Variables to adjust behaviors.

Automation Setup/Import

Automation Configuration

Output

  • Activity Details: Text output indicating if a reboot is required and if conditions were met (e.g., "A reboot is required and all conditions to prompt for reboot have been met.").
  • Custom Fields: Updates cPVAL Pending Reboot, cPVAL Last Prompted, cPVAL Times Prompted, cPVAL Consecutive Missed Prompts, and cPVAL First Missed Prompt Time as part of reset and missed-prompt tracking.
  • Exit Code: Returns 1 to trigger the Autofix script, or 0 if no action is needed or conditions are blocked.

Changelog

2026-07-20

  • Initial version of the document.