How Lightspot works
Lightspot is a small Swift package with no dependencies. This page walks through the source: how the panel is built, what happens on each keystroke, the one rule that keeps typing fast, how CleanDevMac became part of it, how Mac Tweaks is put together, how admin commands run, how it opens System Settings, how only one copy runs and how it updates itself, and how the app is built, released and tested.
Lightspot guide
The source
Lightspot is written in Swift with AppKit and SwiftUI and built with the Swift Package Manager: no Xcode project, no third-party packages. The code is split into three layers:
mac-lightspot/
├── Package.swift Swift 6 package, macOS 13+, no dependencies
├── build.sh release build → build/Lightspot.app and its dSYM
├── install.sh / uninstall.sh
├── THIRD-PARTY-NOTICES.md RemoveMacAI’s and pared’s MIT notices
├── Resources/Info.plist menu bar app (LSUIElement), no Dock icon
├── Resources/cdm-rules/ a copy of CleanDevMac’s rules, the offline fallback
├── scripts/
│ ├── test_engine.swift engine tests
│ ├── deep_verify.swift checks against the live system
│ └── overlay_check.swift the Mac Tweaks and Clean Dev Mac windows, offscreen
└── Sources/Lightspot/
├── AppMain.swift entry point, the --asset-service helper; wires
│ everything with closures
├── Core/ search engine, every result provider, the cdm port,
│ Mac Tweaks’ engine
├── System/ hotkey, menu bar, login item, terminals, Spotlight,
│ single-instance guard, updater
└── UI/ SwiftUI views, the AppKit panel and the tool windows- Core holds the search engine and one provider per kind of result. It uses only Foundation and AppKit, never SwiftUI, and every provider is a shared instance or a static engine.
- System talks to macOS: the global hot key (Carbon
RegisterEventHotKey), the menu bar item, the login item (SMAppService), the seven terminal launchers and the Spotlight switches. - UI is SwiftUI inside an AppKit panel.
AppMain.swiftcreates the view model, the panel, the hot key and the menu bar controller and connects them with closures; there is no dependency-injection container or notification bus.
The panel
The window is a borderless, non-activating NSPanel at the floating level, 740 by 560 points, so it can take keystrokes without pulling the app you were in to the front. Inside it are a 54-point capsule for the search field and a 450-point results area with 26-point corners, both backed by NSVisualEffectView with the HUD material blurring what is behind the window: that is where the Spotlight look comes from. It opens on the screen with the mouse pointer, 16% below the top of the visible area, fading in while scaling from 97% to 100% in 0.18 seconds.
The search field is an NSTextField with its own field editor, so arrow keys, Tab, ↵ with modifiers and the overlay shortcuts reach Lightspot before the text field handles them. The same editor reports text that an input method is still composing, which AppKit does not announce by itself; that was the change in version 1.1.2.
The panel hides whenever it loses focus. That suits a search, but not Mac Tweaks, which sends you to System Settings to approve a profile or to a Touch ID prompt, nor Clean Dev Mac, which can show a folder in Finder or run cdm in your terminal. Up to 1.4.0 both were drawn as layers of the panel and closed half-way. Since 1.4.1 each opens in a window of its own (UI/ToolWindow.swift): an ordinary titled NSWindow, not a panel, so it never hides when Lightspot loses focus. It is movable and resizable from 740 by 450 points, remembers its frame in Lightspot’s defaults (NSWindow Frame MacTweaks, NSWindow Frame CleanDevMac), is dark in both appearances with its title bar transparent over the content, and closes only with its close button, ⌘W, or Esc when no plan is open. The window takes every key itself in sendEvent, before any view sees it, since it has no text field. Opening one hides the panel and activates Lightspot, which a menu bar agent’s panel never does. The window and its SwiftUI view are made at each open and released at each close; a scan, a clean or an apply lives in the provider and keeps running with the window closed.
What happens on a keystroke
Search is synchronous and runs on the main thread, with no debounce. Every change of the text calls the search engine, which asks each provider in turn and merges the answers:
- Applications
- System Settings
- Quick actions
- Process killer
- Custom commands
- Recent projects
- zsh history
- Developer tools
- Hardware readout
- Mac Tweaks
- Clean Dev Mac
- Installers
- Browser
- Clipboard
- Snippets
- Calculator and conversions
- Web search
The engine then adds the learned bonus to each score, picks the Top Hit, sorts every section, cuts it to four results (six for history and browser) and hands the sections to the view in a fixed display order. The display order is an explicit list, deliberately not the order in which the result types are declared, so reordering code cannot silently reshuffle the panel; a test keeps the list complete.
The repository measured a full pass at about 2.8 ms with 7 days of browser history (1,499 pages), 337 bookmarks and 1,200 shell commands in memory, and well under 1 ms without the browser data, which dominates the cost.
The rule that keeps typing fast
Because every provider runs on every keystroke, and SwiftUI re-evaluates menus on every redraw, nothing on the keystroke path may block. The project notes that breaking this rule has happened three times, and each time it was felt the same way: typing became slow. These are the kinds of calls that are not allowed there, with what they cost:
| Call | Cost |
|---|---|
| Asking Chrome for its open tabs over AppleScript | 300–465 ms |
| Asking Finder for the front window’s folder | about 260 ms |
| Running launchctl or mdutil to read Spotlight’s state | about 66 ms |
| Running lsof to map listening ports to processes | about 55–110 ms |
| Parsing 337 Chrome bookmarks | about 12 ms |
| Asking macOS whether the login item is enabled | about 3 ms |
The pattern used everywhere instead: keep a snapshot in memory, return it at once, and refresh it on a background queue when it is stale. A flag marks a refresh in progress, so a burst of keystrokes queues one refresh instead of one per letter. NSAppleScript is not thread-safe, so the browser and Finder queries each get their own serial queue. Where a blocking call is still needed, for example asking Finder for the folder at the moment you press ↵, it is a separate method from the non-blocking one that search uses.
Work that is in memory but grows with the data counts too. Apps, shell commands, browser items and clipboard entries compute their lowercase and tokenised forms once, when they are loaded, not on every search. Substring matching compares UTF-8 bytes directly instead of using String.contains, which goes through Foundation’s collation: about 0.11 µs instead of 3.3 µs against a 90-character title, multiplied by every candidate on every keystroke.
The last exception, the port lookup behind kill :port, which ran lsof inline, became a background snapshot in version 1.2.0, like the process list next to it. The providers added since follow the same pattern: the Clean Dev Mac row only reads the result of the last scan, the Mac Tweaks row is a fixed list of phrases plus the last scan’s total, and the installer rows read whether a tool is installed from a snapshot that is refreshed in the background at most every ten seconds.
CleanDevMac, ported
CleanDevMac (cdm) is a bash program. Clean Dev Mac runs the parts of it that need only the file system in Swift, kept close to the bash so the two can be compared line by line: reading cdm’s rule files, expanding paths with glob(3) under the shell’s rules, measuring folders the way du -sk does by walking them with fts(3) (a category’s folders in parallel, then counted together as one du over all of them would), the Android images still in use and the emulators gone idle, the newest of each version family, old Claude Code sessions, Chrome’s leftover copies, the safety check is_safe_target with its branch for your own temp folders, deleting, the restart estimate and the Claude Code note, and the log with its size cap.
The repo scan is cdm’s scan_projects: one fts walk over the home folder finds folders that hold a .git directory and nominates folders with build or dependency names, then each repo’s own git ls-files listing, run for several repos at once, decides what is really ignored. Two checks are Lightspot’s own: the walk never enters ~/Library or the folders cdm protects, where reading would make macOS ask for permission, and ask again after every update since Lightspot is signed ad hoc; and nothing that holds a repo the walk found is offered. Scans and cleans run on their own queue and publish snapshots; the search row and the window only read them.
Mac Tweaks
Mac Tweaks is built like Clean Dev Mac. Its provider keeps the state of each section (scanning, ready, applying, finished, with the rows and the receipt) on its own serial queue and publishes snapshots, and the search rows and the window only read them. Each section, Free Up Space, Apple Intelligence, Settings and Background Items, is an engine with three calls: scan, apply, and the closing notes of the plan. Rows, plans, progress lines and receipts are plain shared types, which the window only displays, and the provider keeps what each scan read, so the plan and the summary are built from memory and showing them reads nothing.
Nothing runs until you open it. At launch Mac Tweaks reads no file and starts no scan, process or timer, and its window’s model is made the first time you open it; the search rows are fixed lists of phrases, plus the total of the last Free Up Space scan. The main row comes before Clean Dev Mac’s in the search engine, so free up space, which both answer to, makes Mac Tweaks the Top Hit, and its keywords are phrases, so an app’s name, clean, dock or storage stays with its own row. An apply runs on the provider’s queue too and keeps going when you close the window; reopening shows its steps, then the receipt.
Free Up Space ports the storage logic of RemoveMacAI (MIT), and its sizes come from Clean Dev Mac’s du-exact walk. Its own check, isAllowed, runs when a path is offered and again just before it moves: a direct child of one of the row’s folders, fixed in code, as written and with its parent’s symbolic links resolved, never a link itself, never under /System or a folder macOS guards, and an app only with Apple’s bundle identifier. What only an administrator can do is one /bin/sh script: stdin from /dev/null, each command in a subshell of its own followed by a status line that carries a random tag, then exit 0, so a failed step is never taken for a failed prompt. Every argument is single-quoted and every program and path absolute, and a test runs the script with hostile file names (spaces, quotes, $, ;, line breaks, sudo) under both /bin/sh -c and AppleScript’s do shell script. Whatever it did is judged by looking at the disk again.
Apple Intelligence and Settings share one configuration profile, com.lightspot.app.tweaks, built as data: System scope, a restrictions payload, one payload of forced preferences per domain, the download block among them, and a marker domain recording what the profile holds, which Lightspot reads back through macOS’s preferences service to know what is installed. Each payload’s UUID comes from its identifier (version 5 style, SHA-1), so a new profile replaces the old one. One routine changes it for both sections: it writes the file, opens it, opens Device Management a second later and polls the marker once a second for up to 10 minutes; or it removes the profile with profiles remove … -forced as one step of Free Up Space’s administrator script, judged by the marker. Tests check the profile as data and never install, open or remove one.
Apple’s asset framework is never called in Lightspot’s own process. AppKit loads it at launch anyway, but calling it costs 9 to 11 MB of memory that never comes back, so every read and every reset runs in the Lightspot binary started as Lightspot --asset-service, a flag main() handles before the single-instance lock and the app itself start. The child prints one line of JSON and exits; the app gives it 30 seconds for the inventory and 150 for a reset, and a crash, a timeout or an answer it can’t decode changes nothing.
Settings writes your preferences through cfprefsd, as Lightspot already does for Spotlight’s shortcut, and reads each one back before it counts as done. Its undo journal is versioned JSON with one entry per changed thing, saved atomically before the change it records, and each entry keeps what its undo needs, so it can be undone without the catalog that wrote it. A journal that can’t be read is moved aside, never overwritten. Tests write only to scratch preference domains (com.lightspot.test.…) and run the services through a fake launchctl.
Background Items ports RemoveMacAI’s BackgroundItems logic (MIT): its three folders, its verdicts and its launchctl verbs. A plist is opened with O_NONBLOCK and O_NOFOLLOW and read only when it is a regular file of at most 1 MB, so a FIFO or a huge file can’t stall the scan. A symbolic link on the way, to the plist or to the program it runs, is followed one component at a time, and each step is checked before it is looked at against the folders macOS guards, other disks and ~/Library/CloudStorage, in any case and Unicode normalization, as the disk compares names. launchctl runs directly, never through a shell, with stdin from /dev/null and 10 seconds per call, and of launchctl print only the exit status is kept, since its output lists the job’s environment. A label is passed only in printable ASCII, without a slash or a quote: Foundation hands a child process its arguments decomposed, so an accented label would reach launchctl spelled differently from the one launchd compares byte for byte.
A turn-off goes into Settings’ undo journal before launchctl runs, as Background Items’ own JSON, kept byte for byte with every other entry. Undo everything hands the daemons’ steps to the administrator script that removes the profile, so one prompt covers both, and root only ever names a label and a plist the scan found in /Library/LaunchDaemons, never one the journal alone names: the journal is a file your account can write. Tests run the section against fake launchd folders and a fake launchctl.
A delete, added in 1.4.1, is a turn-off plus a move: launchctl bootout while the item runs (a refused bootout changes nothing), launchctl disable, then the plist to the Trash, with trashItem for your own and, for a daemon, a plist another account owns or one in /Library/LaunchAgents, Free Up Space’s guarded mv -n in the administrator script. The journal entry is written first, keeping an earlier turn-off’s entry as the state to go back to, with where the plist was; where it went is added before the prompt for root’s moves and right after the move for your own. It counts only once read again: the plist gone, its copy in the Trash, the label off and nothing running. Undo everything moves the copy back and switches it on as it was, root’s in the same script as the profile’s removal, and as root only for a regular file root owns, with one link and the entry’s label, going back to a name nothing holds in /Library/LaunchAgents or /Library/LaunchDaemons, so editing the journal can’t install a daemon.
Admin commands run once
Admin commands go through sudo on a hidden pseudo-terminal, so that Touch ID can answer when Touch ID for sudo is on, and otherwise through the macOS password dialog. Up to 1.3.9 a command that started under Touch ID and then failed ran again behind the password dialog, and so did one that ran for more than the 60 seconds the Touch ID attempt was allowed.
Since 1.4.0 the command first prints a random marker, written as two halves so that sudo echoing the command line can’t pass for it. Once the marker reaches the terminal, sudo has authenticated and the command has started, so its result is final: no password dialog, no second run. The 60-second limit then stops applying; a 30-minute one remains for a command that hangs. Its stdin becomes /dev/null after the marker, so a command that asks a question doesn’t wait on the hidden terminal, and after it exits Lightspot reads what is left in the terminal for up to a second, so a command that starts and fails between two reads is still seen to have started. Scripts Lightspot builds itself, such as Mac Tweaks’ administrator part, go through a second entry point that leaves the script as it is, with no sudo stripping, and returns its exit status and output. Neither writes a command’s text to the system log, only its outcome.
Opening System Settings
On macOS 27.2, launchservicesd can miss that System Settings has quit and keep its record for a minute or more: 67 seconds once, and a sweep every ten minutes drops the rest. Every open in that time goes to the process that has gone, even when a live System Settings is in front, and macOS shows an alert instead of the pane: “The application "System Settings" is not open anymore.”, or “The application can’t be opened.” with error -600.
So everything Lightspot opens in System Settings, from the settings rows to Mac Tweaks’ profile, goes through one opener. Since 1.4.1 it finds the live System Settings in the process table (your own processes running its executable), never in LaunchServices’ records, and it never asks one to quit:
- A live System Settings with no record of a gone one beside it gets the ordinary quiet open.
- A live one beside such a record gets the Apple Event LaunchServices would have sent (
GURLfor a link,odocfor a file such as the profile), addressed to its process ID, and is then brought to the front, where it opens the pane. On 27.2 the event arrives without an Automation prompt; it is sent so that macOS never shows one. - With only records of processes that have gone, it starts one new System Settings with the link and waits until it shows its window, so the next pane goes to that one.
- With nothing recorded, the ordinary quiet open starts System Settings.
1.4.0 started a new System Settings in these cases and quit a live one to do so, and on 27.2 every quit left one more record of a gone process, so System Settings icons piled up in the Dock. Nothing public makes LaunchServices drop such a record sooner. The opener works on its own queue, so nothing waits on the main thread, and Mac Tweaks’ profile still opens before Device Management. Tests run it against a fake that hands ordinary opens to gone processes as 27.2 does.
One copy at a time
Before it does anything else, Lightspot takes an exclusive lock on ~/Library/Application Support/Lightspot/com.lightspot.app.lock and writes its process ID and a build identity (the executable’s path, inode and modification time) into it. The kernel drops the lock when the process ends, so a crash never leaves a stale lock behind. When a second copy starts:
- If the running copy is the same build, the new one sends it a “show the panel” message and exits, so opening Lightspot from Finder simply shows the search bar. A copy that started less than ten seconds ago ignores that message.
- If it is a different build (reinstalled or rebuilt), the new copy asks the old one to quit, waits up to five seconds, and takes over; if the old copy is still running then, the new one exits instead. While it waits it asks again every half second: a copy that had only just started listening could miss a single request, and up to 1.3.9 the new copy then waited out the five seconds and gave up.
- A copy that an update started waits instead: the old one quits by itself once the new one has finished launching (see the next section).
Both messages are macOS distributed notifications named after the bundle identifier. Copies older than 1.2.0 do not listen for them, so they have to be quit by hand once.
How an update is installed
The update check reads the latest release from the GitHub API and compares versions. Installing downloads the build for this Mac, Lightspot-arm64.zip or Lightspot-x86_64.zip, picked by name from the Mac’s own architecture, as hw.optional.arm64 reports it, never from the architecture Lightspot itself runs as, so a copy running under Rosetta, or carried over from an Intel Mac, moves to the native build. A release without that build, as every release up to 1.3.9, gives the universal Lightspot.zip instead, and the updater never takes the other Mac’s build or the dSYM. The download comes only from GitHub hosts, also after redirects. The updater unpacks it with ditto and checks that the bundle is com.lightspot.app, has its executable, carries exactly the version the release names, and that the executable holds this Mac’s architecture, read from its Mach-O header in Swift: on a Mac without the Command Line Tools, /usr/bin/lipo only offers to install them. There is no signature to check: releases are signed ad hoc, because the project has no Apple Developer ID, so the updater trusts the GitHub release the same way the installer does.
A running app cannot overwrite itself, so Lightspot writes a small shell script to a temporary folder and runs it while Lightspot stays open. The script moves the current app aside, copies the new one in with ditto, removes the quarantine flag and signs it ad hoc. Then Lightspot starts the new version itself and quits only once that copy has finished launching; the new copy waits for the old one to exit before it shows its menu bar item and takes the shortcut, so there is always one Lightspot. If the new version does not finish launching within three minutes, Lightspot stops it, the script puts the old app back, and the old copy keeps running and reports the failure. When the app’s folder is not writable by your account, the script runs with administrator rights, through Touch ID or the password dialog, and hands the app back to your account.
Up to 1.3.3, Lightspot quit first and the script opened the new version. The first launch of a freshly copied and re-signed app waits on a macOS security scan, which can take half a minute, and for that time there was no Lightspot at all.
At rest
When the panel is closed, Lightspot waits for its hot key. The only recurring work is the clipboard check every 0.6 seconds, which compares the pasteboard’s change counter and reads the text only when it changed, and the daily update check. Mac Tweaks adds none, except while an apply you started waits for you to approve its profile in System Settings: it checks once a second, for 10 minutes at most. Hiding the panel, whether with Esc, the hot key or a click outside, clears the result lists and asks the memory allocator to give unused memory back to the system. On my Mac, idle Lightspot processes show 0.0% CPU and between 12 and 30 MB of memory in ps.
Build and release
build.sh doesn’t go through SwiftPM, since neither of SwiftPM’s build systems links LTO objects. It runs one swiftc per architecture over every source file, whole module, optimised for size (-Osize) with exclusivity checks off and full link-time optimisation (-lto=llvm-full), which lets LLVM, and on Apple silicon its machine outliner, see the whole program. It links with no exported symbols, since nothing loads the executable or looks up its symbols, and joins the architectures with lipo. Then it writes the debug symbols to Lightspot.app.dSYM, strips the local symbol names, which were half the binary, with strip -x, wraps the binary into Lightspot.app with its Info.plist and icon, signs it locally and checks that the dSYM’s UUIDs match the app’s. Any step that fails stops the build.
The universal binary of 1.4.0 is 5.1 MB (5,125,248 bytes), 42% smaller than 1.3.9’s 8.8 MB (8,799,968 bytes). On its own, the Apple silicon binary is 2.2 MB and the Intel one 2.9 MB. Nothing changes at run time, since nothing reads the executable’s own symbols; a crash report gets its function names back from the dSYM. The app icon is drawn by a script with Core Graphics and packed with iconutil.
The views write @ViewState where SwiftUI code usually writes @State. From the macOS 27 SDK on, @State is also a macro whose plugin ships only with Xcode, so a build with just the Command Line Tools failed on it; ViewState is the same property wrapper under a name no macro claims, and build.sh refuses a new @State.
Releases are built by GitHub Actions on a macOS runner: a version tag (or a manual run that bumps the version) sets the version in Info.plist and builds the universal app for arm64 and x86_64, then a copy of it for each Mac with build.sh --thin, which thins the binary with lipo, signs it again and checks it. Each release carries four zips. Lightspot-arm64.zip (about 1.6 MB) and Lightspot-x86_64.zip (about 1.75 MB) are what the installer and the updater from 1.4.0 download. Lightspot.zip (about 2.9 MB) stays the universal app under its old name, because the updaters of 1.2.0 to 1.3.9 download exactly that, and so do older links to it; those updaters bring 1.4.0 as the universal build, and the updates after it come thin. Lightspot.app.dSYM.zip holds the debug symbols for all three, since a thinned binary keeps its UUID.
Tests
There is no XCTest target. Instead, three plain Swift programs are compiled together with the sources and run from a clone of the repository:
scripts/test_engine.swiftchecks the engines in 84 test blocks: the calculator and conversions, the fuzzy matcher, every provider, ranking and what search history may keep, custom and pinned commands, settings backup, snippets, the hardware readout, the first-run flow, the Spotlight shortcut state, macOS shortcuts that collide with Lightspot’s, the updater (which download each Mac takes, the architecture check, and a real hand-over between fake app bundles), the single-instance guard, System Settings’ search terms, the recent-project readers of every editor against sample files, Clean Dev Mac (cdm’s rule format, its safety check against cdm’s own test cases, sizing, the categories that work out their offer, your own temp folders, every way of deleting, cdm’s two notes, the repo scan against git fixtures, all in a fake home folder), the installers, the macOS tweaks, which run against a scratch preferences domain, never yours, the System Settings opener against a fake that hands ordinary opens to gone processes as macOS 27.2 does (one new instance at most, pane after pane into it, never a quit), and Mac Tweaks: Free Up Space against a fake system folder and home with stand-ins forxcode-select,simctlandtmutil(each refusal of its check, every row, the Trash, the administrator script with hostile file names, a cancelled prompt, the receipts log); Apple Intelligence against a fake asset service, profile and clock (the helper’s answers and refusals, the client failing closed, the profile as data, the approval wait and the removal in order); Settings on scratch preference domains with a fakelaunchctl(values and types back exactly, the journal saved first, Undo everything, the Dock’s icons, and the Dock’s restart against a fake Dock and clock); and Background Items against fake launchd folders and a fakelaunchctl(what it lists and leaves out, symbolic links, the verdicts, turning off and on, deleting an agent, a leftover, a shared agent and a daemon, the administrator script, the journal and Undo everything putting each back). The public IP lookup is replaced by a stub. The first failure stops the run.scripts/deep_verify.swiftchecks the live system: that every System Settings link names a pane that is installed, that AppleScripts and shell quick actions parse, that the terminals and apps are found, that calculator answers are right, that the “no file indexing” promise holds, and it runs Clean Dev Mac over the real home folder and Mac Tweaks over the Mac without deleting, moving, writing a setting or asking for a password. It has 15 sections, and on my Mac, with macOS 27.2, it runs 206 checks; the number depends on whether the Mac has a zsh history, VS Code projects, git and Xcode.scripts/overlay_check.swift, compiled with every source butAppMain.swift, builds the real Mac Tweaks and Clean Dev Mac windows offscreen on read-only scans of the Mac. It drives each Mac Tweaks section through a rescan and switches to every other section, each run in a child process of its own, so a crash names its section and step, then sends both windows their keys throughsendEvent: the arrows, Space,⌫ in every section, the plan and Esc out of it, Esc to close, a reopen that must build a new window, and ⌘W. Before the fix that went into 1.4.0, the Mac Tweaks overlay crashed in all eight runs. It takes about a minute.
Before a release, the first two are also compiled with the release flags and run, since the app ships LTO code that the plain commands don’t build.
swiftc -o /tmp/test_engine scripts/test_engine.swift Sources/Lightspot/Core/*.swift Sources/Lightspot/System/TerminalLauncher.swift Sources/Lightspot/System/AutoStartManager.swift Sources/Lightspot/System/SpotlightManager.swift Sources/Lightspot/System/FirstRunManager.swift Sources/Lightspot/System/UpdateManager.swift Sources/Lightspot/System/SingleInstanceGuard.swift Sources/Lightspot/System/LegacyNetworkStores.swift Sources/Lightspot/System/HotkeyManager.swift Sources/Lightspot/System/SystemShortcutConflicts.swift && /tmp/test_engineThe project’s history is public: commits on GitHub, from the first commit on 2 September 2026 to the 1.4.3 release on 9 November 2026.