Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndrewWCarson/cd5e0982dd0f1e472a0ce1ed662facf1 to your computer and use it in GitHub Desktop.
Save AndrewWCarson/cd5e0982dd0f1e472a0ce1ed662facf1 to your computer and use it in GitHub Desktop.
This adds an app to the list displayed in System Preferences -> Privacy -> Location Services. It does not enable the app there.
#!/usr/bin/python
import CoreLocation
CLValidAuth = [CoreLocation.kCLAuthorizationStatusAuthorized]
def locationServicesEnabled():
if CoreLocation.CLLocationManager.locationServicesEnabled():
return True
else:
return False
def appLocationAuthorized():
status = CoreLocation.CLLocationManager.authorizationStatus()
if status in CLValidAuth:
return True
else:
return False
def requestLocation():
if not locationServicesEnabled():
exit("Location Services not enabled.")
elif not appLocationAuthorized():
locationMgr = CoreLocation.CLLocationManager.alloc().init()
locationMgr.requestAlwaysAuthorization()
return "Requested permission."
else:
return "Already has Location authorization."
if __name__ == "__main__":
print requestLocation()
@AndrewWCarson
Copy link
Author

From my testing, needs to be run as the logged-in user.

@AndrewWCarson
Copy link
Author

Also, updated to check for Location Services enable status as it has to be on? ¯_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment