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
How to enable Location Services on Mac?
1 2 3 |
output=$(/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -bool true; /bin/launchctl kickstart -k system/com.apple.locationd 2>&1) echo "$output" exit 0 |
Execute this command to enable Location Services on your macOS device.
What happens at the device end?
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?
1 2 3 |
output=$(/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -bool false; /bin/launchctl kickstart -k system/com.apple.locationd 2>&1) echo "$output" exit 0 |
Execute this command to disable Location Services on your macOS device.
What happens at the device end?
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.
How to view the current status of Location Services?
1 |
sudo -u "_locationd" defaults -currentHost read "/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd" |
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.