Skip to main content

Hello,



I'm running into an odd issue that I can't seem to figure out. Since upgrading my image to MacOS Sierra, I can not get Location Services to turn on automatically during or after imaging. I've tried nearly every script and action that I could find on JamfNation, and nothing seems to work.



Does anyone have a method to enable location services? I need to get this enabled so that the time on the machines will be correct. I have been able to set the time manually and with a script to a certain time zone, however we ship our macs to many different time zones for our employees after they are imaged. Would be great to have this set automatically based on location.



Thank you for any suggestions you may have.

I'm currently using this, but have commented out the sections for "#Set an initial time zone" and "#Set specific time server", as these are being set elsewhere. https://www.jamf.com/jamf-nation/discussions/13723/enabling-location-services-programmatically-via-casper#responseChild109407t


@kish.jayson Do you happen to be on Sierra?



I tried that script before posting, and once more with parts of it commented out after reading your comment. It still doesn't seem to be enabling location services.


I am. Tested on both macOS Sierra and OS X El Capitan.


Just out of curiosity, did you reboot the system after running the script? If not, try that and check again. I had a couple of occasions where simply re-loading the LaunchDaemon wasn't enough.


Location Services on 10.12 falls some under SIP, which is most likely why you're seeing this.


Has anyone resolved this? We have just started testing with Sierra and had a script that was working with Yosemite & El Cap; it no longer is, nor do the commands listed in the script that was linked above.



Anyone enabling Location Services before/after imaging in Sierra and how are they doing it?


@MTurnerFMRCO I still haven't found a solution to this issue.


WOuld be interested in solution as well. Have tried many different scripts with no luck yet. I am on Sierra.


Found another post which seems to be working in 12.2.2.
Enabling Location Services Programmatically via Casper



Specifically this piece of the post from @ssrussell



#!/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


So far, this has been working when ran manually or during imaging after reboot.


This script worked perfectly in our environment for 10.12.2!



Thank you @MTurnerFMRCO and @ssrussell for sharing.


@MTurnerFMRCO This worked for me! Thank you and @ssrussell !


I have a mix of El Cap and Sierra devices, so I wrote this little beast, to cover them all:



#!/bin/bash

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

## Get the version of Mac OS
OS_Version=$(sw_vers -productVersion)

if [[ $OS_Version == 10.11* ]] ; then
## Write enabled value to plist (El Cap)
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
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.notbackedup."$uuid" LocationServicesEnabled -int 1
elif [[ $OS_Version == 10.12* ]] ; then
## Write enabled value to locationd plist (Sierra)
defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
fi ## If OS is not 10.11 or 10.12, do nothing

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

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

exit 0


My devices still need a reboot to get it to work, but that does make it work.


Thanks @JayDuff, your script came in handy today


I was having some trouble getting this to work reliably on 10.12.5 and 10.12.6 because of System Integrity Protection, so I reached out to AppleCare Enterprise Support. While not officially supported, the officially unsupported method is below.



sudo defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
sudo chown -R _locationd:_locationd /var/db/locationd

@JayDuff Thanks for sharing your script, Jay. I was working with it in a different manner on yesterday and figured out a pretty slick way to package the script to enable location services in system preferences/security & privacy/privacy so that its a sure-fire hit everytime.



In composer...



Select “new
In the left-hand column select: User Environment “Global Preferences”



This will create the necessary plist “.GlobalPreferences.plist” and seat it under:
/Users/administrator/Library/Preferences/…



You will also notice a second plist under preferences “com.apple.driver.AppleHIDMouse.plist” (which is the action that executes the enabling of the location services feature)



Click the down arrow under the newly created Global Preferences pkg and right click on the scripts folder.
Now, add a “postinstall” script template and insert the following:



!/bin/bash



Unload locationd



/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist



Get the version of Mac OS



OS_Version=$(sw_vers -productVersion)



if p> $OS_Version == 10.11 ]] ; then
## Write enabled value to plist (El Cap)
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
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.notbackedup."$uuid" LocationServicesEnabled -int 1
elif bl $OS_Version == 10.12
]] ; then
## Write enabled value to locationd plist (Sierra)
defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
fi ## If OS is not 10.11 or 10.12, do nothing



Fix Permissions for the locationd folder



/usr/sbin/chown -R _locationd:_locationd /var/db/locationd



Reload locationd



/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist



exit 0



Lastly...
Add the script to the postinstall script template and build as a PKG



You should now have a package that you can drop into Casper Admin



Hope this helps also.








Thanks for sharing your scripts - I doesn't seem to work with High Sierra if SIP is enabled:



If I'm trying to unload the locationd.plist
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist



I'm getting this message:
/System/Library/LaunchDaemons/com.apple.locationd.plist: Operation not permitted while System Integrity Protection is engaged



Do you experience the same issue here?



Best regards 🙂


Jamf hasn't been able to provide a fix for only showing Location Service (After User Registration).
I did also enable Siri now and can see Location Service now.
Hope this will help you all.


You shouldn't need to unload any launch daemons?



See last posts: https://www.jamf.com/jamf-nation/discussions/13723/enabling-location-services-programmatically-via-casper


This works for me in High Sierra + Mojave



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

I am looking for a way to do this in Catalina.


Reply