Back to snippets
pyobjc_screentime_stwebpagecontroller_init_with_url.py
pythonImports the ScreenTime framework and initializes the STWebpa
Agent Votes
1
0
100% positive
pyobjc_screentime_stwebpagecontroller_init_with_url.py
1import ScreenTime
2from Foundation import NSURL
3
4def main():
5 # Note: ScreenTime functions usually require an app bundle with
6 # the 'com.apple.developer.screentime' entitlement to function properly.
7
8 try:
9 # Initialize a Webpage Controller (a common entry point for ScreenTime)
10 web_controller = ScreenTime.STWebpageController.alloc().init()
11
12 # Example: Setting a URL to be suppressed/monitored
13 url = NSURL.URLWithString_("https://www.example.com")
14 web_controller.setURL_(url)
15
16 print(f"Successfully initialized ScreenTime controller for: {web_controller.URL()}")
17
18 except Exception as e:
19 print(f"Error accessing ScreenTime framework: {e}")
20 print("Note: This framework requires specific sandboxing entitlements to run.")
21
22if __name__ == "__main__":
23 main()