Skip to main content
Question

Enabling Location Services in Mountain Lion image

  • September 13, 2012
  • 21 replies
  • 44 views

Forum|alt.badge.img+6

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

21 replies

Forum|alt.badge.img+6
  • Contributor
  • 79 replies
  • October 1, 2012

Sweet testing this now!


Forum|alt.badge.img+5
  • Contributor
  • 96 replies
  • March 15, 2013

Nice, just need a way of adding an item into the Allowed Apps List


antoinekinch11
Forum|alt.badge.img+9
  • Contributor
  • 56 replies
  • June 25, 2013

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?


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • June 25, 2013

@ 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.


antoinekinch11
Forum|alt.badge.img+9
  • Contributor
  • 56 replies
  • June 25, 2013

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.


Forum|alt.badge.img+8
  • Contributor
  • 35 replies
  • September 13, 2013

Cheers for this, man - works great!


Forum|alt.badge.img+5
  • Contributor
  • 64 replies
  • October 9, 2013

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?


Forum|alt.badge.img+13
  • Contributor
  • 400 replies
  • October 9, 2013

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.


Forum|alt.badge.img+5
  • Contributor
  • 64 replies
  • December 26, 2013

Got this running for Mac OS 10.8, but no luck in 10.9.1. Anyone else having problems with the latest OS?


Forum|alt.badge.img+13
  • Contributor
  • 400 replies
  • January 6, 2014

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

armando
Forum|alt.badge.img+12
  • Contributor
  • 19 replies
  • January 8, 2014
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?


Forum|alt.badge.img+13
  • Contributor
  • 400 replies
  • January 8, 2014

@armando][/url
Yes. Works on both OS X 10.8 and 10.9


geoffreykobrien
Forum|alt.badge.img+9
  • Valued Contributor
  • 71 replies
  • July 24, 2014

I couldn't get this to work on 10.9.4, anyone out there enabling this with a never booted image?


Forum|alt.badge.img+21
  • Honored Contributor
  • 970 replies
  • July 26, 2014

Anyone know how to do this in python?


Forum|alt.badge.img+21
  • Honored Contributor
  • 970 replies
  • August 4, 2014

[edited] working in 10.9.4 :)


Forum|alt.badge.img+21
  • Honored Contributor
  • 970 replies
  • August 4, 2014

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

Forum|alt.badge.img+3
  • New Contributor
  • 8 replies
  • November 28, 2016

For me it seems the script doesnt work on OS 10.12.1
Does anyone have tested it on Sierra with any luck?


Forum|alt.badge.img+6
  • Contributor
  • 79 replies
  • January 4, 2017

Yup not working on 10.12 for me as well.


Forum|alt.badge.img+12
  • Contributor
  • 529 replies
  • January 5, 2017

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

Forum|alt.badge.img+13
  • Contributor
  • 400 replies
  • January 5, 2017

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

Forum|alt.badge.img+12
  • Contributor
  • 312 replies
  • March 9, 2017

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