Skip to content

Instantly share code, notes, and snippets.

@rleyvasal
Last active February 9, 2025 01:55
Show Gist options
  • Save rleyvasal/8536b98ce1f25cff875329697575fc0f to your computer and use it in GitHub Desktop.
Save rleyvasal/8536b98ce1f25cff875329697575fc0f to your computer and use it in GitHub Desktop.
Screen Time Allowed Automation Script
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# !pip3 install pyautogui\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"How to set it up:\n",
"1. Run the cell below to get the coordinates of the plus button, the input field, and the done button \n",
"2. Enter each of the X and Y coordinates into the script on the subsequent cell. \n",
"3. Open the settings app and snap it onto the right of the screen on a 15 inch airbook Mac \n",
"4. The script expects a csv file named sorted_domains.csv and a column with heading Domain/IP with all websites in that column \n",
"5. It will wait for 15 seconds. During those 15 seconds, close the settings and open it again to set it up by entering the passcode for allowed websites \n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Move your mouse to the desired button/field\n",
"You have 5 seconds...\n",
"Mouse position: x=1154, y=998\n"
]
}
],
"source": [
"# start from the +\n",
"# import pyautogui\n",
"import time\n",
"\n",
"# Safety settings\n",
"pyautogui.PAUSE = 1\n",
"pyautogui.FAILSAFE = True\n",
"\n",
"print(\"Move your mouse to the desired button/field\")\n",
"print(\"You have 5 seconds...\")\n",
"time.sleep(5)\n",
"\n",
"x, y = pyautogui.position()\n",
"print(f\"Mouse position: x={x}, y={y}\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing websites 111 to 117\n",
"Starting in 15 seconds... Get ready!\n",
"Completed! Processed 7 websites\n",
"Next run will start from index 117\n"
]
}
],
"source": [
"import pyautogui\n",
"import pandas as pd\n",
"import time\n",
"import os\n",
"\n",
"# Safety settings\n",
"pyautogui.PAUSE = 1\n",
"pyautogui.FAILSAFE = True\n",
"\n",
"# Coordinates\n",
"PLUS_BUTTON = (1154, 998)\n",
"\n",
"INPUT_FIELD = (1359, 566)\n",
"DONE_BUTTON = (1508, 631)\n",
"\n",
"# Read progress file if it exists, otherwise start from 0\n",
"PROGRESS_FILE = 'website_progress.txt'\n",
"if os.path.exists(PROGRESS_FILE):\n",
" with open(PROGRESS_FILE, 'r') as f:\n",
" start_index = int(f.read().strip())\n",
"else:\n",
" start_index = 0\n",
"\n",
"# Read CSV file\n",
"df = pd.read_csv('sorted_domains.csv')\n",
"websites = df['Domain/IP'].tolist()\n",
"\n",
"# Process next 10 websites\n",
"end_index = min(start_index + 20, len(websites))\n",
"current_batch = websites[start_index:end_index]\n",
"\n",
"print(f\"Processing websites {start_index + 1} to {end_index}\")\n",
"print(\"Starting in 15 seconds... Get ready!\")\n",
"time.sleep(15) # 15-second pause before starting\n",
"\n",
"for website in current_batch:\n",
" # Click + button\n",
" pyautogui.click(PLUS_BUTTON[0], PLUS_BUTTON[1])\n",
" time.sleep(0.5)\n",
" \n",
" # Click input field and type website\n",
" pyautogui.click(INPUT_FIELD[0], INPUT_FIELD[1])\n",
" time.sleep(0.5)\n",
" pyautogui.write(website)\n",
" time.sleep(0.5)\n",
" \n",
" # Click done button\n",
" pyautogui.click(DONE_BUTTON[0], DONE_BUTTON[1])\n",
" time.sleep(1)\n",
"\n",
"# Save progress\n",
"with open(PROGRESS_FILE, 'w') as f:\n",
" f.write(str(end_index))\n",
"\n",
"print(f\"Completed! Processed {end_index - start_index} websites\")\n",
"print(f\"Next run will start from index {end_index}\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "p3_latest",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment