Skip to content

Instantly share code, notes, and snippets.

@dado3212
Created May 23, 2025 11:44
Show Gist options
  • Save dado3212/bc066ad479162b1bb3eb5ba633893bb5 to your computer and use it in GitHub Desktop.
Save dado3212/bc066ad479162b1bb3eb5ba633893bb5 to your computer and use it in GitHub Desktop.
Script for selecting everything in automation
import subprocess
import Quartz
import time
# Open the Shortcuts app
def is_natural_scroll():
try:
result = subprocess.check_output([
'defaults', 'read',
'NSGlobalDomain',
'com.apple.swipescrolldirection'
])
return result.strip() == b'1'
except subprocess.CalledProcessError:
return True # Default to natural scrolling if key doesn't exist
def user_moved_mouse(since_seconds=0.5):
idle_time = Quartz.CGEventSourceSecondsSinceLastEventType(
Quartz.kCGEventSourceStateHIDSystemState,
Quartz.kCGEventMouseMoved
)
return idle_time < since_seconds
def click_at(x, y):
pt = (x, y)
for event_type in [Quartz.kCGEventLeftMouseDown, Quartz.kCGEventLeftMouseUp]:
event = Quartz.CGEventCreateMouseEvent(None, event_type, pt, Quartz.kCGMouseButtonLeft)
Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
def find_window(title):
from Quartz import CGWindowListCopyWindowInfo, kCGWindowListOptionOnScreenOnly, kCGNullWindowID
window_list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID)
for win in window_list:
if title ==win.get('kCGWindowOwnerName', ''):
return win.get('kCGWindowBounds')
return None
def scroll_vertically(amount, step=30, delay=0.01):
direction = 1 if is_natural_scroll() else -1
scroll_unit = step * direction
steps = abs(amount) // step
for _ in range(steps):
scroll = Quartz.CGEventCreateScrollWheelEvent(None, Quartz.kCGScrollEventUnitLine, 1, scroll_unit)
Quartz.CGEventPost(Quartz.kCGHIDEventTap, scroll)
time.sleep(delay)
remainder = abs(amount) % step
if remainder:
scroll = Quartz.CGEventCreateScrollWheelEvent(None, Quartz.kCGScrollEventUnitLine, 1, remainder * direction)
Quartz.CGEventPost(Quartz.kCGHIDEventTap, scroll)
script = '''
tell application "System Events" to tell process "iPhone Mirroring" to set frontmost to true
tell application "System Events" to tell process "iPhone Mirroring" to set visible to true
delay 1
'''
process = subprocess.run(
['osascript', '-e', script],
capture_output=True,
text=True
)
bounds = find_window("iPhone Mirroring")
if bounds:
x1, y1 = bounds['X'], bounds['Y']
w, h = bounds['Width'], bounds['Height']
# Click the first 14 that are visible, and then swap over to scroll city
for i in range(0, 35):
# Select everything
for i in range(0, 14):
click_at(x1 + w - 50 , y1 + 210 + 36 * i)
if user_moved_mouse():
exit()
time.sleep(0.1)
# Scroll to the next page
scroll_vertically(int(h - 74))
time.sleep(0.45)
else:
print("iPhone Mirroring window not found.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment