Category filter

Script to enable/disable Location Services on macOS devices

Location Services enable several macOS applications and services to gather and use information based on the current location of the Mac, which in turn enhances the user experience. There are certain apps like Maps, for instance, which require the current location of the device to function effectively. This information is collected and provided by Location Services. However, by enabling Location Services the possibility for security threats such as tracking online behavior, theft of identity and lack of privacy in general increases. It is the IT admin’s discretion whether or not to enable/disable Location Services on their fleet of devices.

Location Services can be enabled/disabled for the Mac altogether and if enabled, it can be enabled/disabled for each app/service individually. In this document, we provide scripts which IT admins can use to remotely enable/disable Location Services for macOS devices using Hexnode UEM’s Execute Custom Script action.

Scripting language – Bash

File extension – .sh

Disclaimer:


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

How to enable Location Services on Mac?

Execute this command to enable Location Services on your macOS device.

What happens at the device end?

Location services enabled at the device end under Security & Privacy preferences

On executing the above command, Location Services will be enabled for the device. It will not affect the existing location services setting of individual applications and services.
That is, the apps/services whose checkboxes had previously been marked will be allowed access. Further changes can be made by the admin user at the device end.

How to disable Location Services on Mac?

Execute this command to disable Location Services on your macOS device.

What happens at the device end?

Location services disabled at the device end under Security & Privacy preferences

On executing the above command, Location Services will be disabled for the device. None of the apps/services will be given access to the service.

Notes:

  • The scripts given above are OS version dependent.
  • The above scripts can only enable/disable Location Services. They cannot be used to specify the apps/services that should be given access to the location services.
  • A system restart may be required for the change to be effective.

How to view the current status of Location Services?

Execute this command to check whether Location Services is currently enabled or not. The output can be viewed under the Action History tab of the device.

enabling location services via execute custom script action

Notes:

  • 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