📜 Headless & Scripting
Use the integrated, discrete, auto, and status subcommands non-interactively from shell scripts and automations.
Every mode is available as a direct subcommand, so gpuswitch drops cleanly into shell scripts, aliases, and automations without opening the TUI.
📋 CLI Reference
| Command | Description |
|---|---|
gpuswitch | Open the interactive TUI (↑↓ + enter) |
gpuswitch integrated | Switch to the integrated GPU only |
gpuswitch discrete | Switch to the discrete GPU only |
gpuswitch auto | Let macOS manage GPU switching |
gpuswitch status | Print the current GPU mode |
gpuswitch --help | Show usage (-h also works) |
🚦 Exit codes
- A successful mode switch prints
GPU mode set to: <mode>and exits0. - A failed switch prints
error: failed to set GPU mode to <mode>to stderr and exits1. - An unknown command prints the usage text to stderr and exits
1.
💡 Examples
Save battery before unplugging:
gpuswitch integratedRead the current mode into a variable:
mode=$(gpuswitch status) # → "current GPU mode: integrated"Switch to full performance only when on AC power:
if pmset -g batt | grep -q "AC Power"; then
gpuswitch discrete
else
gpuswitch integrated
fi🔐 sudo and automations
Switching always runs sudo pmset -a gpuswitch <value>, which prompts for a
password. For unattended automations (cron jobs, Raycast scripts, launch
agents), grant passwordless pmset access via a sudoers rule so the command
can run without an interactive prompt:
# /etc/sudoers.d/gpuswitch — edit with `sudo visudo -f /etc/sudoers.d/gpuswitch`
yourusername ALL=(ALL) NOPASSWD: /usr/bin/pmsetGranting passwordless
pmsetwidens what runs without a prompt — scope it to your own user and only enable it if you trust the automation invoking it.