Amphetamine for Mac: Sessions, Triggers, Closed-Display Mode and Scripting

What a session can hold off, which Triggers start one on their own, what keeping a closed MacBook awake asks you to install, and how to tie a session to a build or agent run.

Updated November 23, 2026

Amphetamine is a free keep-awake app for macOS by William Gustafson, distributed through the Mac App Store. It lives in the menu bar and keeps the Mac, and optionally its displays, awake for as long as a session lasts. You can start a session yourself, have a Trigger start one when a condition is met, or script one with AppleScript.

This guide covers what each part does, what keeping a MacBook awake with the lid closed involves on Apple Silicon, how to wrap a long build or AI agent run in a session from the terminal, and where Apple's built-in caffeinate does the same job with less setup.

What Amphetamine is

The developer's App Store listing describes Amphetamine as 100% free: no ads, no in-app purchases and no paid "pro" version. It's a sandboxed App Store app, which matters later: some features need a separate helper because the sandbox stops the app doing them itself.

Under the hood a keep-awake app does what caffeinate does: it holds a power assertion that tells macOS not to idle-sleep. You can see Amphetamine's assertions while a session runs with pmset -g assertions, the same check described in our piece on caffeinate flags. What Amphetamine adds is the control around that assertion: when it starts, what else it holds off, and when it ends.

The listing gives the macOS version it needs and the current version number. Both change, so check the App Store page before relying on a feature described here.

Sessions: how long, and what they hold off

A session is one stretch of keep-awake. From the menu bar icon you can start one that lasts:

  • Indefinitely, until you end it.
  • For a set amount of time, or until a set time on the clock.
  • While a file is downloading.
  • While a specific app is running.

Each session then decides what else to allow or prevent. These are the options the App Store listing names:

OptionWhat it controlsTypical choice for unattended work
Display sleepWhether the screens can turn off while the Mac stays awakeAllow: the job doesn't need the screen
Screen saverWhether the screen saver can startAllow, or leave as it is
System sleep when the built-in display is closedClosed-Display Mode: whether closing a MacBook's lid ends the session's protectionPrevent only if the lid has to be shut; see below
Mouse cursor movementMoves the pointer periodicallyOff: it isn't needed to keep macOS awake
Screen lockingWhether the screen can lock during the sessionAllow, so an unattended Mac stays locked

Amphetamine can also end a session automatically when the battery runs low, which is worth turning on for a laptop left running unplugged.

Triggers: start a session automatically

Triggers are the feature that separates Amphetamine from a plain on/off toggle. A Trigger starts a session while a condition holds and ends it when the condition stops. The listing names these conditions:

  • An external display is connected, or the display is being mirrored.
  • A USB or Bluetooth device is connected.
  • A specific app is running, or running and frontmost.
  • The battery is charging or above a threshold, or the power adapter is connected or disconnected.
  • The Mac has a specific IP address, is on a specific Wi-Fi network, is using specific DNS servers, or is connected to Cisco AnyConnect VPN.
  • Headphones or another audio output is in use.
  • A specific drive or volume is mounted.
  • CPU use is above a threshold, or the Mac has been idle for a set time.

For long-running work, the useful ones are app running (point it at your terminal, IDE or agent app), power adapter connected (only stay awake when plugged in) and CPU use (stay awake while something is busy). Because Amphetamine is sandboxed, app-based Triggers only see regular apps, not command-line processes like node or python. The free Amphetamine Enhancer helper lets Triggers and app-based sessions use every running process.

Add Amphetamine to your Login Items (System Settings → General → Login Items) if a Trigger has to work after a restart: a Trigger can only fire while the app is running.

Closed-Display Mode and Power Protect

Closing a MacBook's lid is forced sleep, not idle sleep, and an ordinary power assertion can't stop it. That's why caffeinate alone won't keep a closed laptop running (see what happens to SSH sessions when the lid closes). Amphetamine's Closed-Display Mode is the session option that keeps the Mac awake with the lid shut.

On Apple Silicon MacBooks it comes with a catch. The developer says Closed-Display Mode may not work as expected after the Mac is connected to or disconnected from power, whether that's a charger or a display that charges it. The fix is Power Protect, a script plus a configuration file that Amphetamine can't install itself, so it's a separate download. When you start a Closed-Display Mode session on an Apple Silicon Mac, Amphetamine offers a link to it.

Know what it installs before you agree. The Power Protect installer asks for Touch ID or an administrator password and places two files:

~/Library/Application Scripts/com.if.Amphetamine/powerProtect.scpt
/private/etc/sudoers.d/amphetamine_powerProtect

The second file is a sudoers rule: it lets the script run a privileged command without asking for a password each time. On a managed work Mac, check with whoever runs the fleet before adding one. To remove the scripts later, use Feedback & Support → Uninstall Scripts… in Amphetamine's menu. If a Closed-Display Mode session was already running when you installed Power Protect, end it and start a new one.

Amphetamine Enhancer also offers a Closed-Display Mode Fail-Safe. Users have reported that the option doesn't appear on some newer MacBook models, so check the Enhancer's issue tracker for your machine.

A closed MacBook that stays awake keeps making heat. Leave it somewhere with airflow, not in a bag, and keep the low-battery auto-end option on if it's unplugged.

If the laptop drives an external display with the lid closed and is plugged in, macOS's own clamshell mode may already keep it running without any of this. Our piece on lid-close behavior with external displays covers when that works and when it doesn't.

Scripting Amphetamine from the terminal

Amphetamine supports AppleScript, so you can start and end sessions with osascript from a shell script, a Makefile or a coding agent's setup hook. These commands are in its scripting dictionary:

# Start an indefinite session (replaces any session already running)
osascript -e 'tell application "Amphetamine" to start new session'

# Start an 8-hour session and let the display sleep
osascript -e 'tell application "Amphetamine" to start new session with options {duration:8, interval:hours, displaySleepAllowed:true}'

# Is a session running? Returns true or false
osascript -e 'tell application "Amphetamine" to session is active'

# End the current session
osascript -e 'tell application "Amphetamine" to end session'

interval takes hours or minutes. The with options record needs all three values (duration, interval and displaySleepAllowed) or none of them. To see every command your installed version supports, open Script Editor, choose File → Open Dictionary… and pick Amphetamine.

Wrap a build or agent run in a session

A timed session is a guess at how long the job takes. Wrapping the job instead ends the session when the job ends, including when it fails or you press Ctrl-C:

#!/bin/zsh
# Keep the Mac awake for exactly as long as the command runs
osascript -e 'tell application "Amphetamine" to start new session'
trap "osascript -e 'tell application \"Amphetamine\" to end session'" EXIT

"$@"

Run it as ./run-awake.sh npm run build, or with your agent's command in place of the build. Two cautions: start new session replaces a session you started by hand, and end session ends whatever session is running when the job finishes. If you keep your own sessions running, check session is active first and only end a session the script started.

For a single terminal command on an open-lid Mac, Apple's built-in tool is simpler: caffeinate -i ./long-job.sh holds the Mac awake until the command exits, and caffeinate -i -w <pid> attaches to a job that's already running. Reach for Amphetamine when you need a closed lid, a Trigger, or one switch that covers work started from several places.

What Amphetamine won't do

  • Work without the app running. It's a menu bar app in your login session. A Mac that restarts for an update and sits at the login window isn't covered, and neither are Triggers until Amphetamine launches.
  • See command-line processes on its own. The sandbox limits app-based Triggers to regular apps unless you install Amphetamine Enhancer.
  • Keep a closed Apple Silicon MacBook reliably awake out of the box. Plugging or unplugging power can upset Closed-Display Mode until Power Protect is installed.
  • Keep connections alive. A Mac that stays awake can still lose an idle SSH or API connection to a network timeout. That's covered in TCP keepalive tuning for overnight agent connections.
  • Keep disks spinning by default. Staying awake and keeping a drive from idling are separate. Amphetamine's Drive Alive feature is for that, much as caffeinate -m is on the command line.

Amphetamine compared with other ways to keep a Mac awake

ToolHow it's controlledLid closedBest for
AmphetamineMenu bar, Triggers, AppleScriptYes, with Closed-Display Mode (Power Protect on Apple Silicon)Conditional rules, closed-lid work, a GUI for people who don't live in Terminal
caffeinateTerminal; built into macOSNo: lid close is forced sleepWrapping one command or process ID; scripts and CI on a Mac
KeepingYouAwakeMenu bar toggle with preset durations; a wrapper around caffeinateNoA free, open-source one-click switch
System Settings or pmsetEnergy and Lock Screen settings, or pmset in TerminalOnly through Apple's clamshell mode, or system-wide changesA dedicated Mac that should never idle-sleep

Our piece on macOS sleep prevention without caffeinate goes through the System Settings toggles, pmset and the other menu bar apps in more depth. On Windows, the closest equivalent is PowerToys Awake.

Installing Amphetamine

  1. Install Amphetamine from the Mac App Store. It's only distributed there.
  2. Open it and start a session from the menu bar icon. Add it to Login Items if Triggers should work after a restart.
  3. Optional: install Amphetamine Enhancer from GitHub if Triggers need to see command-line processes. It's open source and notarized by Apple, and needs Amphetamine 5.0 or later.
  4. Optional, Apple Silicon MacBooks only: install Power Protect if you'll use Closed-Display Mode.

Questions people ask

Is Amphetamine free?

Yes. The developer lists it on the Mac App Store as free, with no ads, no in-app purchases and no paid version.

Can Amphetamine keep a MacBook awake with the lid closed?

Yes, with a session that has Closed-Display Mode on. On Apple Silicon MacBooks the developer recommends installing the separate Power Protect add-on, because connecting or disconnecting power can otherwise interrupt it.

Can I start an Amphetamine session from the command line?

Yes, through AppleScript: osascript -e 'tell application "Amphetamine" to start new session' starts one, and end session ends it. Open Amphetamine's dictionary in Script Editor to see every command.

Should I use Amphetamine or caffeinate?

Use caffeinate to wrap a single command on a Mac with the lid open: it's built in and ends when the command does. Use Amphetamine when you need Triggers, a closed lid, or a menu bar switch.

Sources

  1. Amphetamine - Mac App Store

    Session options, Triggers, features, price, version and system requirements.

  2. Amphetamine Power Protect

    Why Closed-Display Mode needs Power Protect on Apple Silicon, and the files it installs.

  3. Additional Amphetamine Resources - GitHub

    The developer's notes on Closed-Display Mode after power changes on Apple Silicon.

  4. Amphetamine Enhancer - GitHub

    What the helper adds, why it's separate from the sandboxed app, and its requirements.

  5. Start Amphetamine Session With AppleScript

    AppleScript commands and the all-or-nothing options record.

  6. AppleScript discoverability: more Amphetamine

    The session is active command and reading the dictionary in Script Editor.