Category filter

Script to check if Find My Mac is enabled on Mac

Find My Mac is an Apple service that helps users track or locate their macOS devices. It’s essential to have this security feature enabled to safeguard any critical corporate/personal data in case the device is lost or stolen. Admins can check whether ‘Find My Mac’ is enabled or disabled by executing this script with Hexnode’s Execute Custom Script action.

Scripting language – Shell

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Note:


The script works on devices running macOS 10.11 and later.

Check if Find My Mac is set up

/usr/sbin/nvram -x –p: The ‘/usr/sbin/nvram’ command involves the ‘nvram’ utility, which interacts with non-volatile RAM on macOS. ‘-x’ flag specifies the output should be in XML format, and ‘-p’ flag prints all the current NVRAM settings and ‘|’ is a pipe operator which passes the output of the previous command as input to the next command.

/usr/bin/grep fmm-mobileme-token-FMM: The extracted data which is in XML format is filtered using ‘grep’ to find the ‘fmm-mobileme-token-FMM’ string, which corresponds to the ‘Find My Mac’ token.

The ‘if’ condition checks whether the ‘fmmToken’ variable is empty or not. If the token is empty, it means ‘Find My Mac’ is not enabled on the device.

The above script will return the output “Find My Mac is enabled” if ‘Find My Mac’ option is enabled in the device. The output of the script execution can be verified from the Action History page of the device.

Output after executing the script from the portal

If ‘Find My Mac’ option is disabled, the script returns the output as “Find My Mac is disabled”.

Output after executing the script from the portal

The ‘Find My Mac is disabled’ output may also indicate the absence of an associated Apple ID account. Admins can check if an Apple ID account is associated with device or not by using the Script to fetch the Apple IDs of users on Mac.

Notes:

  • The commands used in this script are case sensitive.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository