I am trying to enable Location Services for 10.10 systems via Casper but I cannot find any option with configuration profiles to enable it and the few scripts I have found online do not seem to enable location services.
Specifically I am trying to enable location services to allow for OS X to update the timezone based on the location of the system.
Below is one of the failed scripts I had attempted.
https://www.afp548.com/2013/07/30/enabling-location-services-programmatically/
Best answer by jhbush
@bthomas this has been working for me. I'm not sure where I picked it up from.
There's this discussion from Oct '11 on disabling. I'd think it'd be a simple change to Enable. But I can't get it to work (change Disabled to false to enable is how I understand it).
replace tick with the tick mark from the tilde key (upper left corner on a US keyboard, JAMF Nation interprets this somehow, @jake can this behavior be fixed or changed?
Thank you all for the quick responses however I cannot get the script to enable location services via a policy which calls the the script. I manually ran the on a test system and I believe the problem comes in with the uuid= line because this is the output of grep and cut. I believe the last line is the intended output but I am not that great with scripting to know how to clean up the output.
2015-03-13 19:36:58.810 system_profiler[511:11331] platformPluginDictionary: Can't get X86PlatformPlugin, return value 0
2015-03-13 19:36:58.813 system_profiler[511:11331] platformPluginDictionary: Can't get X86PlatformPlugin, return value 0
564DFCEF-B4E6-7B6A-BE36-42ACC85B9ED0
@jhbush1973 I am running 10.10.2 on my test systems. Production systems are the same OS version. The OS is built using AutoDMG from the 10.10.2 installer downloaded from the Mac App Store.
@jhbush1973 Your script did work for me. I found that it didn't work on my VM due to some weirdness with the hardware ID. I can now enable location services on 10.10.2. Thanks for everyones help!
Works for me. This is the script I use which is meant to use Casper variables which you need to populate.
#!/bin/sh
#Use "/usr/sbin/systemsetup -listtimezones" to see a list of available list time zones.#This script is meant to be used with Casper.# $4 variable should be filled with the TimeZone information (ie: America/Chicago, America/New_York )# $5 variable should be filled with the TimeServer information (ie: time.apple.com )
TimeZone="$4"
TimeServer="$5"############# Pause for network services #############
/bin/sleep 10#######################################################Disable network time
/usr/sbin/systemsetup -setusingnetworktime off
#Set an initial time zone
/usr/sbin/systemsetup -settimezone "$TimeZone"#Set specific time server
/usr/sbin/systemsetup -setnetworktimeserver "$TimeServer"# enable location services
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
uuid=`ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"''/IOPlatformUUID/{print $4}'`
/usr/bin/defaults write /private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd."$uuid" LocationServicesEnabled -int 1
/usr/bin/defaults write /private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.notbackedup."$uuid" LocationServicesEnabled -int 1
/usr/sbin/chown -R _locationd:_locationd /var/db/locationd
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
# set time zone automatically using current location
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true#Re-enable network time
/usr/sbin/systemsetup -setusingnetworktime on
#Detect the timezone
/usr/sbin/systemsetup -gettimezone
#Get the time from time server
/usr/sbin/systemsetup -getnetworktimeserver
exit0
Thank you for sharing. I was concerned about the enable locations services portion and "ioreg" command to get the system uuid but I get why your doing it, very cool.
This seemed like the right place to put this. Been testing my 10.12 first boot script and found that defaults will put the UUID of a ByHost preference in the plist name itself now in 10.12. The original script will actually write the UUID to the plist twice (once by defaults and once by the uuid string) when ran. I removed the uuid stuff from the above script and it works for me. Here is an updated version for 10.12:
#!/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
exit0
Hope this helps and please let me know if there is improvement needed.
@ssrussell I've combined the lengthier script above with your script and I'm not having much luck. I'm in Seattle but as a test I'm setting the initial time zone as "America/New_York" and setting the timer server as "time.apple.com," however even after everything gets reloaded it won't update the time zone to be Seattle or Cupertino or any city in the Pacific time zone.
For clarity's sake, here's the script that I'm trying:
#!/bin/sh#Use "/usr/sbin/systemsetup -listtimezones" to see a list of available list time zones.#This script is meant to be used with Casper.# $4 variable should be filled with the TimeZone information (ie: America/Chicago, America/New_York )# $5 variable should be filled with the TimeServer information (ie: time.apple.com )
TimeZone="America/New_York"
TimeServer="time.apple.com"############# Pause for network services #############
/bin/sleep 10#######################################################Disable network time
/usr/sbin/systemsetup -setusingnetworktime off#Set an initial time zone
/usr/sbin/systemsetup -settimezone "$TimeZone"#Set specific time server
/usr/sbin/systemsetup -setnetworktimeserver "$TimeServer"## 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
# set time zone automatically using current location
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true#Re-enable network time
/usr/sbin/systemsetup -setusingnetworktime on#Detect the timezone
/usr/sbin/systemsetup -gettimezone
#Get the time from time server
/usr/sbin/systemsetup -getnetworktimeserver
The output I'm getting is:
setUsingNetworkTime: Off
Set TimeZone: America/New_York
setNetworkTimeServer: time.apple.com
setUsingNetworkTime: On
Time Zone: America/New_York
Network Time Server: time.apple.com
@cgiordano When you mentioned setting the Time Zone to Seattle or Cupertino are you talking about setting the TimeZone variable to something like: America/Seattle if so, I found that from this command sudo systemsetup -listtimezones which this link has the list, it doesn't have Seattle or Cupertino as options. Your only option is America/Los_Angeles. Using New York and LA worked for me when I used your script and switched them back and forth. I hope I understood your question correctly, but as far as I can tell your script works perfectly.
@ssrussell Maybe I'm misunderstanding the purpose of the script but at the end of the script should it be automatically setting the location? If so, it's not doing that for me. It's leaving the TimeZone set to NY. I thought it was supposed to set the time zone automatically...
@cgiordano I'm sorry, the purpose was basically to click the "Enable Location Services" checkbox under "Security & Privacy" PrefPane. This makes it to where when the user launches an app like Maps.app it'll prompt them to allow Maps to use Location Services (which doesn't require admin rights). If that checkbox isn't checked then it requires admin rights to check it from that "Security & Privacy" PrefPane. This could lead to frustrated non-admin users.
I'm not sure how to check this box, this is what you want:
Yup...I got it now. I guess I was getting confused by the other scripts in this post. I'm not sure the point setting a time zone if we're automatically going to set it via enabling "Set time zone automatically using current location" with the command:
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -booltrue
Wondering the same thing that ssrussell is. Is this possible, because I am not seeing that the apps can be enabled within location services with a non-admin.
@ammonsc@btrabue I'm not sure about how to enable all the items in Location Services programmatically. I'll continue to test and let you know what I find.
@ssrussell Thanks for the Sierra update of this script.
Nevertheless, when I try to run it directly into the Terminal I get an error saying something like "operation not permitted while system integrity protection is engaged". Do you know if this is something I might be doing wrong or a configuration that I need to change in order to integrate this into a larger script?
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.