Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

StayAwake — Keep Your System Awake (macOS, Linux & Windows)

License: MIT Shell Script Platform

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.

Features

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

Requirements

  • macOS: Built-in (uses osascript)
  • Linux: Requires xdotool for 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.Forms access (usually available by default)

Installation

  1. Clone or download the script:
git clone <repository-url>
cd StayAwake
  1. Make the script executable:
chmod +x StayAwake.sh

Usage

Basic Usage (Default Values)

./StayAwake.sh

This will:

  • Press the space key
  • Run for 8 hours (480 minutes)
  • Sleep for a random interval between 5-12 minutes between key presses

View Help

./StayAwake.sh --help

Custom Key

Press the Enter key instead of space:

./StayAwake.sh --key enter

Custom Duration

Run for 2 hours:

./StayAwake.sh --duration 2h

Custom Sleep Range

Press keys at random intervals between 1-3 minutes:

./StayAwake.sh --sleep-range 1m:3m

Combine Options

Press Tab key, run for 1 hour 30 minutes, with 2-5 minute intervals:

./StayAwake.sh --key tab --duration 1h30m --sleep-range 2m:5m

Time Format

The 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 minutes
  • 2h30m45s = 2 hours 30 minutes 45 seconds
  • 1d4h = 1 day 4 hours
  • 90 = 90 seconds

Supported Keys

Special Keys

  • space - Spacebar
  • enter or return - Enter/Return key
  • tab - Tab key
  • escape - Escape key
  • backspace - Backspace key
  • delete - Delete key
  • shift - Shift key
  • ctrl - Control key
  • alt - Alt key
  • cmd - Command key (macOS)

Arrow Keys

  • left, right, up, down

Letters and Numbers

  • Any letter: a, b, c, ... z
  • Any digit: 0, 1, 2, ... 9

Examples

Keep Awake During a Presentation (30 minutes)

./StayAwake.sh --duration 30m --sleep-range 3m:5m --key space

Long Download Session (2 hours)

./StayAwake.sh --duration 2h --sleep-range 5m:10m --key space

Office Work (Full Day)

./StayAwake.sh --duration 8h --sleep-range 10m:15m --key tab

Night Coding Session (6 hours)

./StayAwake.sh --duration 6h --sleep-range 2m:4m --key a

Output

When 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
======================================

Stopping the Script

To stop the script before it completes:

  • Press Ctrl+C in the terminal

Tips & Tricks

  1. Minimal Disturbance - Use space or tab keys to minimize visible effects
  2. Longer Intervals - Use longer sleep ranges to reduce battery drain on laptops
  3. Testing - Use --duration 5m --sleep-range 30s:1m for quick testing
  4. Background Execution - Run in background with:
    ./StayAwake.sh --duration 8h &

Troubleshooting

Linux - Key presses not working

  • Ensure xdotool is installed: which xdotool
  • Try running with explicit key: ./StayAwake.sh --key space

Windows - PowerShell errors

  • Run PowerShell as Administrator
  • Check if System.Windows.Forms is available

macOS - Permission denied

  • Make sure script is executable: chmod +x StayAwake.sh
  • May require granting accessibility permissions to Terminal in System Preferences

All Platforms - Script runs but doesn't prevent sleep

  • The script simulates key presses, but some applications/systems may ignore them
  • Try different keys with --key option
  • Some power-saving modes may override the key presses

Operating System Detection

The script automatically detects your OS on startup:

  • macOS - Darwin-based systems
  • Linux - Linux distributions
  • Windows - Windows via PowerShell
  • Unknown - Unsupported systems

Platform Compatibility

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

Performance

  • Memory: Minimal (< 5MB)
  • CPU: Minimal when idle
  • Battery: Low impact (short key presses at intervals)

License

This project is open source and available under the MIT License.

Contributing

Feel free to fork this repository and submit pull requests with improvements!

Support

For issues or questions:

  1. Check the troubleshooting section above
  2. Run ./StayAwake.sh --help to verify command syntax
  3. Create an issue in the repository with details about your OS and the command used

Related Searches

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.

About

Cross-platform bash script to keep your computer awake — prevents sleep/screen-lock on macOS, Linux & Windows by simulating key presses. Caffeinate/Mouse-Jiggler alternative.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages