Posted on 09-13-2012 07:38 AM
Enabling Location Services in our Mountain Lion image has been driving me crazy. After some googling and playing with fseventer, I was able to throw together the following script that works in our image workflow at reboot.
#!/bin/bash
launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
uuid=`/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57`
defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1
chown -R _locationd:_locationd /var/db/locationd
launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
Posted on 10-01-2012 11:50 AM
Sweet testing this now!
Posted on 03-15-2013 04:49 AM
Nice, just need a way of adding an item into the Allowed Apps List
Posted on 06-25-2013 08:57 AM
I am testing this now but an already getting the following error: Could not write domain /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.XXXXX.
Any luck with this?
Posted on 06-25-2013 09:22 AM
@ bajankinch, is the script running from a Casper policy or otherwise being run with root privileges? The "locationd" directory and everything underneath it in /var/bd/ is locked so unless it runs as root it will never be able to write to that location.
Posted on 06-25-2013 09:26 AM
I tried running the commands with sudo, I am going to test deploying the script through Casper Remote and at reboot at the time of imaging today.
Posted on 09-13-2013 08:12 AM
Cheers for this, man - works great!
Posted on 10-09-2013 02:34 PM
I'm missing something. I tried this as a login script, no luck. I tried it in Self Service, got this error from the policy -
Running script EnableLocationServices.sh...
Script exit code: 0
Script result: usage: sudo -h | -K | -k | -L | -V
usage: sudo -v [-AknS] [-g groupname|#gid] [-p prompt] [-u user name|#uid]
usage: sudo -l[l] [-AknS] [-g groupname|#gid] [-p prompt] [-U user name] [-u
user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-g groupname|#gid] [-p prompt] [-u user
name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C fd] [-g groupname|#gid] [-p prompt] [-u user
name|#uid] file ...
This is the script command -
#!/usr/bin/env bash
#enables Location Services
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
sudo uuid='/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57'
sudo defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1
sudo chown -R _locationd:_locationd /var/db/locationd
sudo launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
I've been having other problems with running "first run" scripts since moving to 10.8.4. Any ideas?
Posted on 10-09-2013 03:45 PM
please copy the script from the very first post and use it.
You don't need "sudo" when you runs scripts with Casper as Casper run them as root.
Posted on 12-26-2013 01:19 PM
Got this running for Mac OS 10.8, but no luck in 10.9.1. Anyone else having problems with the latest OS?
Posted on 01-05-2014 08:31 PM
You have to have an additional line to get it work with 10.9
Use this;
#!/bin/sh
# enable location services
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
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
/usr/sbin/chown -R _locationd:_locationd /var/db/locationd
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
Posted on 01-08-2014 08:59 AM
You have to have an additional line to get it work with 10.9 Use this; #!/bin/sh # enable location services /bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist 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 /usr/sbin/chown -R _locationd:_locationd /var/db/locationd /bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
Can I use this for both 10.8 and 10.9?
Posted on 01-08-2014 02:32 PM
@armando][/url
Yes. Works on both OS X 10.8 and 10.9
Posted on 07-24-2014 03:12 PM
I couldn't get this to work on 10.9.4, anyone out there enabling this with a never booted image?
Posted on 07-26-2014 01:14 AM
Anyone know how to do this in python?
Posted on 08-03-2014 11:23 PM
[edited] working in 10.9.4 :)
Posted on 08-04-2014 01:38 AM
I've used this to set the system time :)
#!/bin/bash
########################## SET SYSTEM TIME ##################################################
#
# Written by Tim Kimpton
#
# using information from https://jamfnation.jamfsoftware.com/discussion.html?id=5336
#
# If the machine is 5 minutes out of the kdc the machine will not bind to the domain.
#
# This script does the folling to ensure the time is correct
#
# 1. Unload the launch daemon used for location services
#
# 2. Get the hardware UUID of the machine and put it in the location services db
#
# 3. Enable location services
#
# 4. Correct permissions on the database file used for location services
#
# 5. Set the time zone to update the time automatically
#
# 6. Set the network time to on
#
# For information see https://jamfnation.jamfsoftware.com/discussion.html?id=5336
###############################################################################################
######################### ENVIRONMENT VARIABLES #######################
# Get the Hardware UUID from system profiler
uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)
####################### DO NOT MODIFY BELOW THIS LINE #################
# Unload the launch daemon
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
# Write the UUID to the hidden plist file and initialise it
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd."$uuid" LocationServicesEnabled -int 1
# Enable Location Services
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.notbackedup."$uuid" LocationServicesEnabled -int 1
# Make sure the permissions on the database file is correct
/usr/sbin/chown -R _locationd:_locationd /var/db/locationd
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
# Set time zone to update automatically
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true
# Set network time to on
/usr/sbin/systemsetup -setusingnetworktime on > /dev/null 2>&1
exit 0
Posted on 11-28-2016 12:39 AM
For me it seems the script doesnt work on OS 10.12.1
Does anyone have tested it on Sierra with any luck?
Posted on 01-04-2017 11:34 AM
Yup not working on 10.12 for me as well.
Posted on 01-04-2017 04:07 PM
Try this:
#!/bin/bash
mac_uuid=$(defaults read /Library/Preferences/com.apple.apsd.plist MachineUniqueIdentifier)
ld_plist=/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.${mac_uuid}.plist
plist_buddy="/usr/libexec/PlistBuddy"
location_status=$(${plist_buddy} -c 'print :LocationServicesEnabled ' "$ld_plist" 2>/dev/null)
case $location_status in
0)
$plist_buddy -c 'set :LocationServicesEnabled 1' "$ld_plist"
;;
1)
echo "Nothing to do"
;;
*)
$plist_buddy -c 'add :LocationServicesEnabled integer 1' "$ld_plist"
;;
esac
launchctl kickstart -k system/com.apple.locationd
exit 0
Posted on 01-04-2017 04:14 PM
macOS 10.12 needed a little change with the script.
Working script:
#!/bin/sh
# Enable location services
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.notbackedup LocationServicesEnabled -int 1
/usr/sbin/chown -R _locationd:_locationd /var/db/locationd
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
Posted on 03-09-2017 11:03 AM
Been a long time since I've been here but I just wanted to say thanks for sharing!
Didn't have this issue in org but a buddy just bought a new MacBook Pro and it had this oob. Script worked great!
:D