Skip to main content

Is there no way to do this? As far as I'm aware this is being stopped by SIP.

There was this script to enable them but it's no longer working.

#!/bin/bash

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

## Write enabled value to locationd plist
defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1

## Fix Permissions for the locationd folder
chown -R _locationd:_locationd /var/db/locationd

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

exit 0

Looking for something that works with SIP enabled in HighSierra, does not look promising though..


I simply use this script. No load or unload of the LaunchDaemon is necessary:

#!/bin/bash

# write enabled key
sudo -u _locationd /usr/bin/defaults -currentHost write com.apple.locationd LocationServicesEnabled -int 1

# enable icon in menu bar
/usr/bin/defaults /Library/Preferences/com.apple.locationmenu "ShowSystemServices" -bool YES

exit 0

Hi @gda.. your script is working except in the "enable icon menu bar" you forgot the write command.. but yes.. this works....

Well i've only tested on 10.13.3. Does it work with 10.12.x?

#!/bin/bash

# write enabled key
sudo -u _locationd /usr/bin/defaults -currentHost write com.apple.locationd LocationServicesEnabled -int 1

# enable icon in menu bar
/usr/bin/defaults write /Library/Preferences/com.apple.locationmenu "ShowSystemServices" -bool YES

exit 0

@rqomsiya Thx for fixing it. 😆Being in a WebEx and filtering scripts is not a good combination.

But yes, I use this script since 10.12.3.


Not a problem! haha..

And awesome.. thanks for verifying its working on 10.12.6. Do you push this out as part of an imaging workflow or part of a login hook?


I used it in the imaging workflow. But you can use it as a checkin policy also.


Awesome.. Thanks for confirming!


@rqomsiya When I run the script I get this on enabling the icon on the menu bar

Could not write domain /Library/Preferences/com.apple.locationmenu; exiting


@loza8454 Running this with elevated permissions with sudo made this successful for me.

@rqomsiya Thanks for that script! Can confirm it works on 10.12.6 as well as 10.13.6. Saves us a step in the First Run Setup process, now we can hide the option for Location Services!


Getting "Could not write domain com.apple.locationd; exiting" as well.

executed the following: sudo -u _locationd /usr/bin/defaults -currentHost write com.apple.locationd LocationServicesEnabled -int 1


This works for me in High Sierra + Mojave

/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1

Thank you @sshort, finally got it to work with the line you provided. Confirm the preference can be set on 10.13.6 and 10.14


@sateshb Can you share what you did to get it to work? I have tried "/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1" with sudo and sudo -u _locationd with no luck, Still getting 2018-10-27 17:31:33.409 defaults[5798:171447] Could not write domain /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd; exiting


Why this is not part of the MDM spec BOGGLES THE MIND.


@csa, not sure why its not working for you, here is a snippet from my script

#!/bin/sh

#Turning on location services
if [[ $locationStatus = 1 ]]; then
    echo "Location Service is turned on"
    else
        echo "Enabling location Service"
        sudo /usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
        if [[ $locationStatus = 1 ]]; then
            echo "Location Service has been turned on"
        fi
fi


I'm going to pose an additional question here as well. I am working with my Jamf Buddy but can anyone share how to enable Set time zone automatically using current location in System PreferencesData & TimeTime Zone?


@sateshb you can use this:

/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true

Thanks for getting back to me Steve, I tried that but didn't make a difference. Ran Composer to take a before and after snapshot and don't see the com.app.timezone.auto plist in the list. Can't imagine where this preference is hiding.


Hi, I was able to configure Location Services and configure automatic timezone using the following lines.
A restart is required because restarting the related launchdaemons is no longer possible because of SIP.

enabling location services

/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1

uuid=/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1

configure automatic timezone

/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeOnlyEnabled -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeZoneEnabled -bool YES

/usr/sbin/systemsetup -setusingnetworktime on
/usr/sbin/systemsetup -gettimezone
/usr/sbin/systemsetup -getnetworktimeserver


Hey Fabian, thank you for this. One minor tweak is on your line with uuid=

uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)

added $( )

Works great, thanks!


My attempt at fixing the formatting on @fabianhartmann's script...

#!/bin/bash

# enabling location services

/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1

uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1

# configure automatic timezone

/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeOnlyEnabled -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeZoneEnabled -bool YES

/usr/sbin/systemsetup -setusingnetworktime on
/usr/sbin/systemsetup -gettimezone
/usr/sbin/systemsetup -getnetworktimeserver

@sdagley This worked Flawlessly! Mojave 10.14.5

Thank You!


@CorpIT_eB Thanks for the confirmation. Credit goes to @fabianhartmann though. I just put his script into a code block to make it readable on the forum.


@fabianhartmann Thanks for the code and @sdagley thanks for adding it to a proper block.


Suggestion: don't use system_profiler command inside a script. It takes a ridiculously long time to work and outputs in a not nice way to parse later. The cut command used is evidence of that. What you can do instead is this:

uuid=$( /usr/sbin/ioreg -d2 -c IOPlatformExpertDevice | awk -F" '/IOPlatformUUID/{print $(NF-1)}' )

This runs in a fraction of the time.