Last active
July 23, 2021 00:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
From my testing, needs to be run as the logged-in user.
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
Since Python doesn't have the necessary keys in their Info.plist for a proper request, this is a best effort attempt to get Python access to Location Services via manual approval.