Posted on 02-12-2018 12:09 PM
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
Posted on 03-08-2018 07:21 AM
Looking for something that works with SIP enabled in HighSierra, does not look promising though..
Posted on 03-09-2018 12:03 AM
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
Posted on 03-09-2018 12:20 AM
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
Posted on 03-09-2018 12:25 AM
@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.
Posted on 03-09-2018 12:27 AM
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?
Posted on 03-09-2018 12:29 AM
I used it in the imaging workflow. But you can use it as a checkin policy also.
Posted on 03-09-2018 12:30 AM
Awesome.. Thanks for confirming!
Posted on 05-08-2018 12:18 PM
@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
Posted on 09-19-2018 10:17 AM
Posted on 10-26-2018 08:37 AM
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
Posted on 10-26-2018 09:27 AM
This works for me in High Sierra + Mojave
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
Posted on 10-26-2018 11:14 AM
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
Posted on 10-27-2018 02:34 PM
@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
Posted on 10-29-2018 11:37 AM
Why this is not part of the MDM spec BOGGLES THE MIND.
Posted on 11-02-2018 07:34 AM
@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
Posted on 11-02-2018 08:58 AM
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?
Posted on 11-02-2018 09:39 AM
@sateshb you can use this:
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true
Posted on 11-02-2018 10:01 AM
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.
Posted on 02-01-2019 06:20 AM
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.
/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
/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
Posted on 05-09-2019 10:27 AM
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!
Posted on 05-09-2019 11:37 AM
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
Posted on 06-03-2019 12:58 PM
@sdagley This worked Flawlessly! Mojave 10.14.5
Thank You!
Posted on 06-03-2019 01:33 PM
@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.
Posted on 06-03-2019 01:47 PM
@fabianhartmann Thanks for the code and @sdagley thanks for adding it to a proper block.
Posted on 07-14-2019 11:46 PM
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.
Posted on 07-15-2019 09:52 AM
@franton to be clear the only thing that would change would be the variable correct everything else would stay the same.
From:
uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)
To:
uuid=$( /usr/sbin/ioreg -d2 -c IOPlatformExpertDevice | awk -F" '/IOPlatformUUID/{print $(NF-1)}' )
Posted on 07-16-2019 02:17 AM
@CorpIT_eB correct! that'd be the only change. (I just have this thing about not running system_profiler in scripts)
Posted on 08-12-2019 01:01 PM
@sdagley Does this script require a reboot before it works?
Posted on 08-12-2019 02:47 PM
@kericson I believe it does. I run this script with several others as part of my initial configuration process which ends in a restart to enable FileVault so I haven't tried it without rebooting.
Posted on 12-10-2019 11:02 PM
@sateshb would you mind sharing how you read the value for location services? I'm trying to get an Extension Attribute so I can scope a smart group around it, but my scripting isn't good enough to grab that value.
#!/bin/bash
locationservices=(/usr/bin/defaults read /private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled)
if [[ $locationservices = 1 ]]; then
result=Enabled
else
result=Disabled
fi
echo <result>$result</result>
Edit: Got it sorted, I missed the space after the '1' and the ']]'.
Posted on 01-08-2020 11:17 AM
i get a "does not exist" even though location services is enabled and the timezone is set to auto on my machine, albeit manually.
im reading as i dont want to commit and am testing to see if it sees anything before i make changes, just i case i want to make an EA to scope things
C02YJ17VJHD4:~ ME$ /usr/bin/defaults read /private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled
2020-01-08 12:14:37.504 defaults[88421:6521570]
The domain/default pair of (/private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd, LocationServicesEnabled) does not exist
also this
C02YJ17VJHD4:~ ME$ /usr/bin/defaults read /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.2322ECE6-78B2-52A1-8F95-59C31793488A LocationServicesEnabled
2020-01-08 12:16:52.069 defaults[88432:6537060]
The domain/default pair of (/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.2322ECE6-78B2-52A1-8F95-59C31793488A, LocationServicesEnabled) does not exist
any suggestions?
EDIT:
it seems to be a permission issue.
tested by giving myself permission to the locationd to test and i got a "1" result.
removed access and it got the error.
ran same command with sudo and i get a result of "1"
will continue to test.
Posted on 02-04-2020 08:17 PM
Jamf is running the command as root hence no sudo in anything else above.
Posted on 05-11-2021 12:36 PM
Create a blank package with the script below. Then add it to your prestage enrollment.
#!/bin/bash
## configure ntp server
/bin/cat > /etc/ntp.conf << 'NEW_NTP_CONF'
server time.apple.com
NEW_NTP_CONF
## configure automatic timezone
/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
## Set date and time automatically
/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
### Restart location services daemon (locationd)
/usr/bin/killall locationd
exit 0; ## Success
exit 1; ## Failure
Posted on 05-18-2021 03:33 PM
@bwoods Does this require a reboot to apply?
Posted on 05-19-2021 06:55 AM
@KyleEricson No reboot required, it works immediately. Perfect for DEP/ADE deployments.