@bearzooka You're getting that error because the script is trying to unload that System Daemon. I'm not sure if that is a 10.12.4 thing. I was originally running this outside a user session over the loginwindow, but if it is a SIP thing, it shouldn't matter where it is being run from. You can still run the defaults write
command, it just may not be applied until a reboot occurs. I'll test this and let you know what I find.
Because I have to work on fixing time zone settings too I found an easy way to enable location services.
I just ran this command in a root shell to enable the location services without a reboot.
sudo -u _locationd defaults write -currentHost com.apple.locationd LocationServicesEnabled -int 1
And this command to disable location services:
sudo -u _locationd defaults write -currentHost com.apple.locationd LocationServicesEnabled -int 0
@gda Thanks for those commands, real slick! Using sudo to run as locationd and using -currentHost so folks don't need to fiddle with UUIDs or file ownership issues. Looking at a lot of the code out there, mine included, I can't believe I haven't grasped currentHost before this! Although I've found defaults in 10.12+ will automatically append the UUID when you write to a ByHost path... anyway the currentHost option needs to be declared immediately after the command and before the "action verb":
Enabling Location Services:
sudo -u _locationd defaults -currentHost write com.apple.locationd LocationServicesEnabled -int 1
Disabling Location Services:
sudo -u _locationd defaults -currentHost write com.apple.locationd LocationServicesEnabled -int 0
Note: This still works in 10.14
Update: I misspoke, things are actually quite messed up in 10.14.0
This works for me in High Sierra + Mojave
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
@sshort Please share how you got this to work in High Sierra and Mojave. Location services are now protected by SIP I get the following error:
2018-10-27 18:51:44.864 defaults[7230:223088] Could not write domain /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd; exiting
Just to update, my above post...
Writing to the plist as locationd does not work in in Mojave (sorry too many test laptops
Despite the file being owned by locationd:_ locationd you indeed get the "Could not write domain" error
What's more and worse is that despite this it will allow you to write to the plist as root:
bash-3.2# ls -l /private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd*
-rw------- 1 root wheel 148 Oct 30 10:11 /private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.57B6A0CC-1731-5A1B-A795-004AD89C0060.plist
-rw------- 1 root wheel 74 Oct 30 10:12 /private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.notbackedup.57B6A0CC-1731-5A1B-A795-004AD89C0060.plist
The really really bad downside to this is that if you unlock the Privacy Preference pane and check "Enable Location Service" it is unable to write those changes to disk! Despite checking and unchecking those plists don't budge, and if you leave it checked and reboot, you'll find it unchecked when it comes back up. Even if you write 1 as the value, because of the file mode, locationd can't read the plist and the only way to fix the permissions is to reboot in Recovery, where you can change ownership back to locationd
Yeah... I hope they fix this in 10.14.1 prolly too late for a bug report... of course, this is just Apple forcing their hand to let users run as admins, which I am all for, treat adults like adults... of course Macs are in education and everyone being an admin is not always ideal. Having Date/Time and Location prefs in MDM would be the ideal way to manage this
Although the command stated by @sshort did enable Location Service for Mojave and High Sierra, it was not enabling it for the specific apps. Is there a way around to enable location services for a specific app like Safari etc since loading and unloading of locationd.plist is prevented by SIP ? Thanks.
@brunerd thanks for the fix. ;-)
I tested again on 10.14.1 and it worked fine for me.
Location services got enabled on my client & test client as soon as I ran the command:
sudo -u _locationd defaults -currentHost write com.apple.locationd LocationServicesEnabled -int 1
Appears Apple cut off the above solutions in Mojave. This defaults command works for me on 10.4.1 as of today...
sudo defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
FYI - confirmed that @nstrauss solution works on 10.14.0, 10.14.1 and 10.14.2. Thank you so much, we have been trying to this working for a while.