Auto Enable Location Services

JaimeVF
New Contributor

Hello there,

Is there any way to automatically enable Location Services for non-admin users?

I know it is currently not possible to set up a PPPC, so I tried some scripts to enable this feature.

For example:

 

#!/bin/bash

#set -x

##########################################################################################
##
## Script to enable automatically Location Services on Mac
##
##########################################################################################

## Define variables
location_enabled=$(sudo -u "_locationd" defaults -currentHost read "/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd" LocationServicesEnabled)

## Check if location services is enabled. If so, we will terminate this script immediately. Otherwise, we will enable it. 

echo " $(date) | Checking if this macOS-device has Location Services enabled or not..."
if [[ "$location_enabled" = "1" ]]; then
	echo " $(date) | Location Services are already enabled"
    exit 0
else
	echo " $(date) | Location Services disabled. Enabling..."
fi

## Enable Location Services
sudo /usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
sudo /usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true
    
# Checking activation
if [ "$?" = "0" ]; then
    echo " $(date) | Location Services is now enabled"
else
    echo " $(date) | Failed to enable Location Services"
    exit 1
fi

 

The scripts seems to work, but when I check through the GUI it shows Location Services disabled:

JaimeVF_0-1740389562354.jpeg

I also tried with a script from Jamf Support, but with the same result:

 

#!/bin/sh

# Unload location services
launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist

# Get device UUID
uuid=`/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57`

# Enable location services
defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1
defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1

# Set proper ownership
chown -R _locationd:_locationd /var/db/locationd

# Reload location services
launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist

# Enable automatic timezone
defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true

exit 0

 

 Is it something that enables Location Services but doesn't show up in the GUI?

2 ACCEPTED SOLUTIONS

AJPinto
Esteemed Contributor

Like with screen recording, this is one of the things Apple decrees is within the user sphere and there is no way to programmatically enable location services. Configuration Profiles nor scrips will work, the user must do this themselves in the GUI.

View solution in original post

Hi @AJPinto,

Okay, that's what I was thinking. Thanks for confirming it.

View solution in original post

3 REPLIES 3

AJPinto
Esteemed Contributor

Like with screen recording, this is one of the things Apple decrees is within the user sphere and there is no way to programmatically enable location services. Configuration Profiles nor scrips will work, the user must do this themselves in the GUI.

Hi @AJPinto,

Okay, that's what I was thinking. Thanks for confirming it.

@AJPinto is correct.  @JaimeVF make sure to mark it as a solution to help other users find the answer quickly.