StayAwake is a free, open-source, cross-platform bash script that prevents your computer from sleeping, locking, or going idle by simulating periodic key presses (space, enter, tab, or any key you choose). It's a lightweight, scriptable alternative to caffeinate, Amphetamine, Mouse Jiggler, Insomnia, KeepAwake, and other "prevent sleep" / "stay awake" apps — with no GUI required and full control from the command line.
Use it to keep your system active during long downloads, video calls, presentations, remote sessions (SSH/RDP), CI jobs, VPN connections, screen shares, or any time your OS's idle/sleep timer gets in the way.
Keywords: keep computer awake, prevent sleep script, stay awake mac terminal, caffeinate alternative linux, disable sleep mode bash script, keep mac awake command line, prevent screen lock windows powershell, auto key press script, mouse jiggler alternative, no-sleep script, idle prevention tool, keep system active during download, presentation mode keep awake.
✅ Cross-Platform Support - Works on macOS, Linux, and Windows ✅ Custom Key Support - Press any key (space, enter, tab, letters, numbers, arrow keys, etc.) ✅ Flexible Duration - Specify duration with easy-to-read time format ✅ Configurable Sleep Range - Set random intervals between key presses ✅ OS Detection - Automatically detects and logs your operating system ✅ Help Command - Built-in help documentation ✅ Progress Tracking - See progress percentage and remaining time
- macOS: Built-in (uses osascript)
- Linux: Requires
xdotoolfor key simulation# Ubuntu/Debian sudo apt-get install xdotool # Fedora sudo dnf install xdotool # macOS (using Homebrew) brew install xdotool
- Windows: PowerShell with
System.Windows.Formsaccess (usually available by default)
- Clone or download the script:
git clone <repository-url>
cd StayAwake- Make the script executable:
chmod +x StayAwake.sh./StayAwake.shThis will:
- Press the space key
- Run for 8 hours (480 minutes)
- Sleep for a random interval between 5-12 minutes between key presses
./StayAwake.sh --helpPress the Enter key instead of space:
./StayAwake.sh --key enterRun for 2 hours:
./StayAwake.sh --duration 2hPress keys at random intervals between 1-3 minutes:
./StayAwake.sh --sleep-range 1m:3mPress Tab key, run for 1 hour 30 minutes, with 2-5 minute intervals:
./StayAwake.sh --key tab --duration 1h30m --sleep-range 2m:5mThe script supports flexible time formatting:
| Unit | Symbol | Example |
|---|---|---|
| Days | d | 2d (2 days) |
| Hours | h | 3h (3 hours) |
| Minutes | m | 30m (30 minutes) |
| Seconds | s | 45s (45 seconds) |
| No Unit | - | 120 (120 seconds) |
Combined Examples:
1h20m= 1 hour 20 minutes2h30m45s= 2 hours 30 minutes 45 seconds1d4h= 1 day 4 hours90= 90 seconds
space- Spacebarenterorreturn- Enter/Return keytab- Tab keyescape- Escape keybackspace- Backspace keydelete- Delete keyshift- Shift keyctrl- Control keyalt- Alt keycmd- Command key (macOS)
left,right,up,down
- Any letter:
a,b,c, ...z - Any digit:
0,1,2, ...9
./StayAwake.sh --duration 30m --sleep-range 3m:5m --key space./StayAwake.sh --duration 2h --sleep-range 5m:10m --key space./StayAwake.sh --duration 8h --sleep-range 10m:15m --key tab./StayAwake.sh --duration 6h --sleep-range 2m:4m --key aWhen you start the script, you'll see:
======================================
StayAwake Script
======================================
Operating System: macOS
Key to press: space
Total duration: 10h 0m 0s
Sleep range: 5m 0s - 12m 0s
======================================
Starting in 3 seconds...
Running... (5% - 570m remaining)
Running... (10% - 540m remaining)
...
======================================
Stopped after 600 minutes
Total key presses: 47
======================================
To stop the script before it completes:
- Press Ctrl+C in the terminal
- Minimal Disturbance - Use
spaceortabkeys to minimize visible effects - Longer Intervals - Use longer sleep ranges to reduce battery drain on laptops
- Testing - Use
--duration 5m --sleep-range 30s:1mfor quick testing - Background Execution - Run in background with:
./StayAwake.sh --duration 8h &
- Ensure
xdotoolis installed:which xdotool - Try running with explicit key:
./StayAwake.sh --key space
- Run PowerShell as Administrator
- Check if
System.Windows.Formsis available
- Make sure script is executable:
chmod +x StayAwake.sh - May require granting accessibility permissions to Terminal in System Preferences
- The script simulates key presses, but some applications/systems may ignore them
- Try different keys with
--keyoption - Some power-saving modes may override the key presses
The script automatically detects your OS on startup:
- macOS - Darwin-based systems
- Linux - Linux distributions
- Windows - Windows via PowerShell
- Unknown - Unsupported systems
| Platform | Key Presses | Status |
|---|---|---|
| macOS 10.13+ | ✅ Full Support | Tested |
| Ubuntu 18.04+ | ✅ Full Support (with xdotool) | Tested |
| Windows 10/11 | ✅ Full Support | Tested |
| Other Linux | ✅ Full Support (with xdotool) | Should work |
- Memory: Minimal (< 5MB)
- CPU: Minimal when idle
- Battery: Low impact (short key presses at intervals)
This project is open source and available under the MIT License.
Feel free to fork this repository and submit pull requests with improvements!
For issues or questions:
- Check the troubleshooting section above
- Run
./StayAwake.sh --helpto verify command syntax - Create an issue in the repository with details about your OS and the command used
People also look for this kind of tool as: keep awake script, caffeinate for linux/windows, prevent sleep bash script, stop screen lock script, anti-idle script, mouse jiggler cli, keep zoom/teams active, no-sleep terminal utility, presentation mode script, keep ssh session alive.
If StayAwake solved this for you, consider starring ⭐ the repo — it's the single biggest factor in how high a project ranks in GitHub search.