gen3ric-labs
← AI Lab Work

Mac & automation · Mar–Apr 2026 · with Claude Delivered B+

Small Mac automations

Two scripts too small for their own project: one that restarts a memory-hungry app overnight, and one that wrote my agenda.

Two small problems, two small scripts

This entry is about automations that are too small for their own project: each one fixed an annoyance, took an afternoon, and kept running.

1. The desktop app that ate memory overnight

One of the chat apps I keep open all day (an Electron app, which is a web page in its own browser shell) grew steadily until the Mac felt sluggish. Diagnosing it was the useful part: the tell is memory that grows steadily while the app sits idle and drops straight back down after a restart. That pattern is a leak. I can't fix someone else's app, so the practical answer was to restart it on a schedule while I sleep.

The script quits the app politely, waits, force-quits only if needed, and relaunches it. This is a generic version of the pattern, not the exact script I run:

#!/bin/bash
# restart-app.sh : quit an app cleanly, wait, relaunch it
APP="MyApp"                                   # the app's process name

osascript -e "tell application \"$APP\" to quit" 2>/dev/null

for i in $(seq 30); do                        # give it up to 30 s to quit
  pgrep -x "$APP" >/dev/null || break
  sleep 1
done
pkill -x "$APP" 2>/dev/null                   # still there? force it
sleep 2
open -a "$APP"

launchd runs it at 3 a.m. The agent definition is a few lines:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
  <key>Label</key><string>com.example.restart-app</string>
  <key>ProgramArguments</key>
  <array><string>/bin/bash</string><string>/Users/you/bin/restart-app.sh</string></array>
  <key>StartCalendarInterval</key>
  <dict><key>Hour</key><integer>3</integer><key>Minute</key><integer>0</integer></dict>
</dict></plist>

I wrote the install, verify and disable steps down at the same time, because an automation you can't switch off isn't finished:

# install
cp com.example.restart-app.plist ~/Library/LaunchAgents/
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.restart-app.plist

# verify it is loaded, then test it right now
launchctl print gui/$(id -u)/com.example.restart-app | head
launchctl kickstart -k gui/$(id -u)/com.example.restart-app

# disable
launchctl bootout gui/$(id -u)/com.example.restart-app

2. An agenda that writes itself

Earlier, when my notes still lived in Apple Notes, I wrote an AppleScript that read the week's events from Calendar and created a note for each day inside a weekly folder. The folder tree mirrored the one I already used for projects. It needed no extra software, and it was already in daily use when I wrote this up. My notes have since moved to Obsidian (more on that move).

What these have in common

This is entry 04 of AI Lab Work.