tinyapps.org · 12d · discuss
Seeking a simpler mouse jiggler than WakeyWakey, move-mouse-macOS, or MoveMouse, queried Opus 5.5; it conjured up tinynudge in one shot, just 30 lines of Swift and 54k compiled: // tinynudge: Prevent sleep with 1px cursor nudges when idle and a caffeinate-style power assertion // Build: swiftc -O tinynudge.swift -o tinynudge && strip tinynudge Usage: tinynudge [seconds] (default 60, Ctrl-C to quit) import ApplicationServices import IOKit.pwr_mgt setbuf(stdout, nil) let interval = max(1, Double(CommandLine.arguments.dropFirst().first ?? "") ?? 60) var assertion = IOPMAssertionID(0) IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep as CFString, IOPMAssertionLevel(kIOPMAssertionLevelOn), "tinynudge" as CFString, &assertion) if !AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeUnretainedValue(): true] as CFDictionary) { print("tinynudge: Grant Terminal Accessibility access (\"Device Control and Data Access\" on macOS 27+) in System Settings → Privacy & Security, then rerun.") } print("tinynudge: every \(Int(interval))s when idle. Ctrl-C to quit.") let anyInput = CGEventType(rawValue: ~0)! func move(_ p: CGPoint) { CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: p, mouseButton: .left)?.post(tap: .cghidEventTap) } while true { sleep(UInt32(interval)) // Only nudge if the mouse/keyboard hasn't been touched for at least half an interval. guard CGEventSource.secondsSinceLastEventType(.hidSystemState, eventType: anyInput) >= interval / 2 else { continue } guard let p = CGEvent(source: nil)?.location else { continue } move(CGPoint(x: p.x + 1, y: p.y)) move(p) } Checks input idle time every N seconds (default: 60). If idle for at least N seconds, moves the cursor 1px right and back. Requires Accessibility access ("Device Control and Data Access" in macOS 27+); prompts if your terminal lacks it. Separately, holds a caffeinate -d-style power assertion, visible as tinynudge in pmset -g assertions. Keeps the display awake without Accessibility access; released on exit.