6 Replies Latest reply: Nov 6, 2015 10:49 AM by Upshot IT
John Lockwood Level 6 Level 6
expertise.desktops
Desktops

It is possible in Mountain Lion or Mavericks to turn on location services via a shell script as might be used via Apple Remote Desktop or DeployStudio or similar. An example script to do this is listed below.

 

#!/bin/sh
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
uuid=`/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep "Hardware UUID" | /usr/bin/cut -c22-57`
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1
chown -R _locationd:_locationd /var/db/locationd
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
exit 0

 

The script turns location services off, finds the Macs unique hardware UUID number, sets the preference file for this Mac which has a file name unique to this Mac because the file name includes the UUID number, restores ownership of the file as the defaults command will have possibly changed the owner, and then turns location services back on.

 

As mentioned the above will work for Mountain Lion and Mavericks. Unfortunately Lion even though it also has location services its method of confuguring is totally different.

 

Does anyone have a similar command line solution to enable location services for Lion (aka OS X 10.7).

  • tausifkhan1324 Level 1 Level 1

    THis should work:

    #!/bin/sh

    launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist

    defaults write /System/Library/LaunchDaemons/com.apple.locationd Disabled -bool false

    launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist

     

    exit 0

  • Upshot IT Level 1 Level 1

    Hi John,

     

    Thanks for posting this. Do you know if your script will work in Yosemite and El Capitan?

     

    We image our computers with Casper Suite, but location services is off at the end of the imaging process. I want to enable it, post-imaging, with a script such as yours.

  • John Lockwood Level 6 Level 6
    expertise.desktops
    Desktops

    I am using basically the same script as part of my DeployStudio workflow and it still works with Yosemite, I have not yet tested it with El Capitan but see no reason it will not continue to work.

     

    There is one issue that I did come across which maybe a problem for you. Apart from simply turning it on which the script does, the way OS X works is that applications needs to also be authorised via the Privacy tab to be allowed to use Location Services. This involves adding them to a plist file at

     

    /var/db/locationd/clients.plist

     

    Unfortunately the structure of this file does not make it modifiable via the standard defaults command. I ended up building a running system, enabling location services, and manually authorising the application(s) I wanted, then copying that pre-configured file during my DeployStudio workflow along with turning on Locations Services as detailed previously.

  • Upshot IT Level 1 Level 1

    Hi John,

     

    I just tried your script on three test computers (two Yosemites, and one El Capitan), and I can confirm that Location Services checks ON.

     

    On one of my Yosemite machines, I logged in as a Standard user (non-admin), and opened the Notification Area. When I saw the little window that Weather would like to use location services, I clicked OK. I then looked in the Security & Privacy > Privacy pane, and Weather is checked ON.

     

    I'm hoping that if any of my users (who are not admins) launch an app that would like to use the service, that it will also check ON for them.

  • John Lockwood Level 6 Level 6
    expertise.desktops
    Desktops

    Upshot IT wrote:

     

    Hi John,

     

    I just tried your script on three test computers (two Yosemites, and one El Capitan), and I can confirm that Location Services checks ON.

     

    On one of my Yosemite machines, I logged in as a Standard user (non-admin), and opened the Notification Area. When I saw the little window that Weather would like to use location services, I clicked OK. I then looked in the Security & Privacy > Privacy pane, and Weather is checked ON.

     

    I'm hoping that if any of my users (who are not admins) launch an app that would like to use the service, that it will also check ON for them.

    It may depend on whether you have also configured your Mac to require admin access to enable various System Preferences. Also waiting for a user to do the above relies on them remembering to do so and also means until they do so it is not active.

     

    For most cases e.g. the Weather one, this will hardly be critical, when I was testing this I was doing something a lot more sneaky. As a test I setup a command line service which would allow me to query the physical location of a Mac using location services and then report it to Casper Suite. I don't do this for real live systems but merely to see if it could be done which the answer was yes.

  • Upshot IT Level 1 Level 1

    These three machines have the "Require an administrator password to access system-wide preferences" checked ON.