The glowmoth CLI: Commands, Leases and Exit Codes
glowmoth CLI reference: install the tool, start and stop sessions, run and wait, leases, status --json fields, exit codes, errors and caffeinate equivalents.
Updated 8 min read
On this page
This page is a reference for the glowmoth command-line tool (the glowmoth CLI). It covers installing it, every command, how leases work, what status returns, and the exit codes and errors you may see. The tool ships inside Glowmoth, so there is nothing extra to download.
Install the glowmoth CLI
- Open Glowmoth Settings. Right-click the menu bar icon and choose Settings…, or click Settings… in the panel footer (⌘,, Command-Comma).
- Go to the Advanced tab.
- Under Command Line, next to Command-line tool, click Install.
Glowmoth creates a symlink at ~/.local/bin/glowmoth that points to Glowmoth.app/Contents/Helpers/glowmoth. The Uninstall button in the same place removes the symlink.
If your shell can't find glowmoth, add ~/.local/bin to your PATH. For zsh, the default shell on macOS:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrcThis command appends one line to ~/.zshrc. Open a new Terminal window for the change to take effect. To undo it, delete that line from ~/.zshrc.
The tool talks to the running app over a Unix socket at ~/Library/Application Support/Glowmoth/glowmoth.sock. Only processes running as your own user can connect.
Start, stop and toggle a session from Terminal
| Command | What it does |
|---|---|
glowmoth on | Starts your session with the Default duration from Settings ▸ Sessions. Alias: start. |
glowmoth off | Stops your session. Automatic reasons are not affected. Alias: stop. |
glowmoth toggle | Starts your default duration, or stops the running session. |
glowmoth for <duration> | Keeps the Mac awake for a length of time. |
glowmoth until <time> | Keeps the Mac awake until a clock time. |
glowmoth extend <minutes> | Adds time, or removes it with a negative number. Alias: adjust. |
These commands control the same session as the panel and the menu. For example, glowmoth off also ends a session you started with a click.
on, for and until accept two optional flags. --display keeps the screen on too. --no-display keeps the Mac awake but lets the display sleep.
If Glowmoth isn't running, on, for, until, toggle and extend launch it in the background and print Started Glowmoth. The off, status and lease commands don't launch the app. Instead they print Glowmoth isn't running. and exit with code 2.
Durations and times for for, until and extend
fortakes minutes or a duration, for exampleglowmoth for 90,glowmoth for 1h30orglowmoth for "2h 15m". A plain number means minutes. A timed session can last at most 7 days. For anything longer, use an open-ended session (glowmoth onwith Default duration set to Indefinitely, which is the default).untiltakes a clock time, such asglowmoth until 18:00orglowmoth until 6pm. If that time has already passed today, the session runs until that time tomorrow.extendtakes minutes, such asglowmoth extend 30orglowmoth extend -15.
What extend does depends on the current state:
- With no session, a positive number starts a timed session of that length.
- On an open-ended session, a positive number makes the session end that many minutes from now.
- On a timed session, the minutes are added to or removed from the end time. If the new end time would fall within the next minute, the session stops instead.
Keep the Mac awake for a command or a process
glowmoth run --label "Nightly build" -- make release
glowmoth wait 4182run [--label <text>] [--display | --no-display] -- <cmd…>keeps the Mac awake while the command runs. Put the flags before--.runpasses Ctrl-C through to the command and returns the command's exit code. If the command was killed, it returns 128 plus the signal number. If the command couldn't start, it returns 127.wait <pid>keeps the Mac awake until that process exits. It also accepts--label <text>.
Both commands hold the Mac through a lease and send a heartbeat every 10 seconds. If the Glowmoth app isn't running, or goes away partway through, they create their own power assertion named glowmoth: <label>. So run and wait keep working in scripts even when the menu bar app is closed, much like caffeinate <command> and caffeinate -w.
There is one exception. If the app is running but has no valid license or trial, it accepts the lease but holds no assertion, so the Mac can still sleep. run and wait fall back to their own assertion only when they can't reach the app at all.
Leases, heartbeats and TTLs
A lease is a named hold that a script or agent keeps renewing while it works. If the script dies without releasing it, the hold ends on its own once the TTL runs out.
glowmoth lease acquire --id nightly-backup --label "Nightly backup" --ttl 1h
glowmoth lease heartbeat --id nightly-backup --ttl 1h
glowmoth lease release --id nightly-backupacquirecreates the lease. It also accepts--displayor--no-display. Without--display, a lease keeps only the system awake and the display can sleep.heartbeatrenews the lease. It also accepts--ttl.releaseends the lease.- TTL: from 5 to 86,400 seconds, with a default of 300. You can write it as
300,300s,5mor1h. The lease ends when its TTL passes without a heartbeat. - Limits: an id can be up to 128 characters and a label up to 200.
Leases appear in the panel as "Command Line" reasons. Clicking ✕ on a lease's row removes it. Leases count as automatic reasons. Manual mode ignores them, and Stop Everything suspends them until you start your next session.
status and status --json
glowmoth status prints the state on its first line: "Awake until 18:00 today", "Awake", "Sleep allowed", or the reason for a safety pause. One line follows for each active reason, in the form · <reason> (until …).
The command exits with 0 when the Mac is being kept awake, 1 when it isn't, and 2 when Glowmoth isn't running. This makes it easy to check from a script:
if glowmoth status >/dev/null; then echo "Mac is being kept awake"; figlowmoth status --json returns these fields. Dates are in ISO 8601 format.
| Field | Contents |
|---|---|
state | "idle", "awake" or "paused" |
awake | Whether the Mac is held awake |
keepsDisplayOn | Whether the display is kept on |
pausedReason | The safety-pause reason, when paused |
endDate | An end date, when one is set |
sessionEnd | The end of your own session |
holders[] | One entry per reason: id, kind, label, expiry, wantsDisplay |
When the app isn't running, it prints:
{"awake":false,"running":false,"state":"not-running"}Other commands
glowmoth agent --event <name> [--message <text>]is meant for coding-agent hooks. Suppose the message is a usage-limit notice with a reset time, such as "…limit reached ∙ resets 5am (Europe/London)". Glowmoth then schedules a run that starts 2 minutes before the reset and lasts 30 minutes. A newer notice replaces the previous run. Without--message, the command reads the hook's JSON from stdin. It always exits 0, and scheduling a run needs a license. Other events are accepted and ignored for now. See scheduled runs and agent limit resets.glowmoth help(also-hor--help) prints the usage text.glowmoth version(also--versionor-v) prints the version.
Exit codes
| Code | When |
|---|---|
| 0 | status: the Mac is being kept awake. agent always returns 0. |
| 1 | status only: the Mac isn't being kept awake. |
| 2 | Glowmoth isn't running (off, status, lease …). |
| 64 | The arguments couldn't be read. |
| The command's own code | run returns the child's exit code. It returns 128 plus the signal number if the child was killed, or 127 if the child couldn't start. |
Error messages and fixes
| Message | Fix |
|---|---|
Installed. Add ~/.local/bin to your shell's PATH if glowmoth isn't found. | Add the PATH line from the install section. |
~/.local/bin/glowmoth already exists and isn't Glowmoth's. Remove it first. | Move or delete that file, then click Install again. |
Couldn't install the tool: … / Couldn't remove the tool: … | The text after the colon gives the cause. Check that you can write to ~/.local/bin. |
Tooltip The tool is missing from this copy of Glowmoth. | Download Glowmoth again from macsuite.app and reinstall it. |
glowmoth: Glowmoth isn't running. | Open Glowmoth, or run glowmoth on, which launches it. |
Glowmoth needs a license. Open Glowmoth to activate it. | Enter your MacSuite license in Glowmoth. |
Couldn't read “…”. Try 90, 1h30 or 2h 15m. | Fix the duration you passed to for. |
Couldn't read “…”. Try 18:00 or 6pm. | Fix the time you passed to until. |
extend needs a number of minutes. / extend takes minutes, like 30 or -15. | Pass a number of minutes. |
wait takes a process ID. / glowmoth: No process with ID N. | Check the PID, for example with pgrep <name>. |
Usage: glowmoth run -- <command> | Put -- before the command. |
glowmoth: Couldn't run X: … | Check the command's name and path. |
A lease needs an --id. / A lease needs an --id of up to 128 characters. / lease X needs --id <id>. | Pass --id with 128 characters or fewer. |
No lease “<id>”. It may have expired; acquire it again. | The TTL passed without a heartbeat. Run acquire again, and send heartbeats more often or use a longer TTL. |
--ttl takes seconds, like 300 or 5m. | Use a TTL from 5 seconds to 1 day. |
Unknown lease command: X / Usage: glowmoth lease acquire|heartbeat|release --id <id> | Use acquire, heartbeat or release. |
Unknown command: X. Run glowmoth help. / Unexpected argument: X | Check the spelling against glowmoth help. |
Glowmoth is shutting down. | Reopen Glowmoth, then retry. |
glowmoth and caffeinate equivalents
The caffeinate command built into macOS covers some of the same jobs. These are the closest matches:
| caffeinate | glowmoth |
|---|---|
caffeinate -i (prevent idle system sleep) | glowmoth on --no-display |
caffeinate -d (prevent display sleep) | glowmoth on --display |
caffeinate -t 3600 | glowmoth for 1h |
caffeinate -w <pid> | glowmoth wait <pid> |
caffeinate <command> | glowmoth run -- <command> (returns its exit code) |
-s, -m, -u | No equivalent |
Note that glowmoth on uses your default duration, which is Indefinitely unless you change it.
glowmoth also gives you labeled reasons in the panel, leases with TTLs, safety pauses for low battery and heat, and status --json. If you run caffeinate yourself, it shows up in Glowmoth's "Also Keeping This Mac Awake" list with the purpose "caffeinate". See what's keeping your Mac awake.