Posted on 11-18-2019 10:41 AM
I have a number of computers that I manage and previously I've been able to enable Location Services by running the following command in terminal or via a script:
defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
With Catalina however, that command doesn't work anymore. Does anyone have any ideas or suggestions on another method of managing this setting?
Posted on 11-18-2019 11:23 AM
From the talk at the latest Apple/Jamf Boston meetup, it doesn't sound like this is manageable anymore for privacy reasons. Unknown if management of it will come to supervised T2 devices...
Posted on 11-18-2019 12:08 PM
@rick.cohen It wouldn't surprise me that it'd break under Catalina, but I don't think the example you posted works under Mojave either. Here's what I've been using to modify the ByHost entry specific to the machine:
#!/bin/bash
# enabling location services
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
Posted on 12-17-2019 04:37 AM
@sdagley This was on Mojave or Catalina?
Here's what I've been using to modify the ByHost entry specific to the machine:!/bin/bash
enabling location services
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
Posted on 12-17-2019 06:36 AM
@G.M. That was for Mojave. I think it works for Catalina, but could use independent verification.
P.S. if you're pasting a script into a discussion, please use the code block tag (triple backtick ```) before and after it so the forum software doesn't mangle the display.
Posted on 03-03-2020 01:36 PM
I just tested this in Catalina and it didn't work for me. Has anybody found a solution that works?
Posted on 03-05-2020 11:34 AM
Under Catalina it seems there are 2 spots where the key "LocationServicesEnabled" is stored. I have experienced that both spots must have the same values to have an effect on the LocationServices under macOS Catalina.
If you read the key out via sudo -u "_locationd" defaults -currentHost read "com.apple.locationd.<UUID>"
your result will be:
{
LocationServicesEnabled = 1;
}
And via sudo defaults read "/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd"
you will get following:
{
"CLSilo.Version" = 1;
LastSystemVersion = "Mac OS X10.15.3/19D76";
LocationServicesEnabled = 1;
ObsoleteDataDeleted = 1;
}
So we have to write to both spots to enable the LocationServices. I have tested it under macOS 10.15 and 10.15.3.
#!/bin/bash
uuid=$("/usr/sbin/system_profiler" SPHardwareDataType | grep "Hardware UUID" | awk '{ print $3 }')
prefDomain="com.apple.locationd.$uuid"
byHostPath="/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd"
# read booleans
ls_enabled_uuid=$(sudo -u "_locationd" defaults -currentHost read "${prefDomain}" LocationServicesEnabled)
ls_enabled_byhost=$(sudo defaults read "${byHostPath}" LocationServicesEnabled)
# process booleans
if [[ $ls_enabled_uuid && $ls_enabled_byhost ]]; then
echo "Location Services are already enabled."
else
# set booleans
sudo -u "_locationd" defaults -currentHost write "${prefDomain}" LocationServicesEnabled -int 1
sudo defaults write "${byHostPath}" LocationServicesEnabled -int 1
fi
Unfortunately, the change only applies after a restart as long as SIP is enabled.
Otherwise the Launch Daemon could simply be unloaded and reloaded after the change.
Test yourself in Terminal:
$ sudo launchctl unload "/System/Library/LaunchDaemons/com.apple.locationd.plist"
Password:
/System/Library/LaunchDaemons/com.apple.locationd.plist:
Operation not permitted while System Integrity Protection is engaged
@rmgmedia @rick.cohen Did that help you?
Posted on 03-06-2020 07:11 AM
So we have to write to both spots to enable the LocationServices. I have tested it under macOS 10.15 and 10.15.3.!/bin/bash
uuid=$("/usr/sbin/system_profiler" SPHardwareDataType | grep "Hardware UUID" | awk '{ print $3 }') prefDomain="com.apple.locationd.$uuid" byHostPath="/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd"read booleans
ls_enabled_uuid=$(sudo -u "_locationd" defaults -currentHost read "${prefDomain}" LocationServicesEnabled) ls_enabled_byhost=$(sudo defaults read "${byHostPath}" LocationServicesEnabled)process booleans
if [[ $ls_enabled_uuid && $ls_enabled_byhost ]]; then echo "Location Services are already enabled." else # set booleans sudo -u "_locationd" defaults -currentHost write "${prefDomain}" LocationServicesEnabled -int 1 sudo defaults write "${byHostPath}" LocationServicesEnabled -int 1 fi Unfortunately, the change only applies after a restart as long as SIP is enabled. Otherwise the Launch Daemon could simply be unloaded and reloaded after the change. Test yourself in Terminal: $ sudo launchctl unload "/System/Library/LaunchDaemons/com.apple.locationd.plist" Password: /System/Library/LaunchDaemons/com.apple.locationd.plist: Operation not permitted while System Integrity Protection is engaged @rmgmedia @rick.cohen Did that help you?
Hi @alex.duffner
I tried running the script you posted above and I saw the following in the logs after running it.
Script result: 2020-03-06 07:01:39.086 defaults[38860:1401723]
The domain/default pair of (/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd, LocationServicesEnabled) does not exist
Any idea what I'm doing wrong?
Posted on 03-06-2020 01:33 PM
This is what I use as a script. I have not had any issues with Catalina but have not tested in about a month.
#!/bin/sh
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
Posted on 03-06-2020 01:33 PM
This has been a futile battle for a while now, some alternatives are showing the Location page on Pre-staged enrollment and allow the owner to enable location services and/or prompt the users with a message and open the system preference page. The Plist approach only works on low version operating systems.
Posted on 03-12-2020 03:35 AM
@rmgmedia What do you get if you execute the following?
sudo -u "_locationd" defaults -currentHost read "/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd"
Posted on 03-12-2020 06:54 AM
@alex.duffner I get this:
{
"CLSilo.Version" = 1;
LastSystemVersion = "Mac OS X10.15.3/19D76";
LocationServicesEnabled = 1;
ObsoleteDataDeleted = 1;
}
Posted on 03-13-2020 06:25 AM
@rmgmedia So if you get what you posted you should also be able to read the specific key (LocationServicesEnabled) out, via:
sudo -u "_locationd" defaults -currentHost read "/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd" LocationServicesEnabled
# you should get a return of "1" (without the double quotes)
But I believe that the following code will work on most systems, including Catalina:
My detailed script above (#1 post of mine on this thread) is just in case this wont work.
sudo -u "_locationd" defaults -currentHost write "/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd" LocationServicesEnabled -int 1
Posted on 03-13-2020 07:34 AM
@alex.duffner
After seeing the results to the previous command you posted, I decided to try the script again and it seems to be working now. The reboot is required but that is not a problem for me.
Thanks again for your help.
Posted on 01-28-2021 10:22 AM
I just tested @jsuski two command lines in Big Sur and they worked. Did require a reboot.
Posted on 05-19-2021 06:38 AM