{"id":50534498,"url":"https://github.com/ddasy/sleepbar","last_synced_at":"2026-06-03T16:00:38.448Z","repository":{"id":362236413,"uuid":"1258000196","full_name":"ddasy/SleepBar","owner":"ddasy","description":"🌙 A lightweight macOS menu bar timer to auto lock, sleep, or keep your Mac awake after a countdown.","archived":false,"fork":false,"pushed_at":"2026-06-03T07:36:41.000Z","size":373,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-03T09:22:43.286Z","etag":null,"topics":["appkit","auto-lock","caffeinate","display-sleep","keep-awake","macos","macos-app","menu-bar","menubar","productivity","screen-lock","sleep-timer","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ddasy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-03T07:32:11.000Z","updated_at":"2026-06-03T07:36:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ddasy/SleepBar","commit_stats":null,"previous_names":["ddasy/sleepbar"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ddasy/SleepBar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddasy%2FSleepBar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddasy%2FSleepBar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddasy%2FSleepBar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddasy%2FSleepBar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddasy","download_url":"https://codeload.github.com/ddasy/SleepBar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddasy%2FSleepBar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33872298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-03T02:00:06.370Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appkit","auto-lock","caffeinate","display-sleep","keep-awake","macos","macos-app","menu-bar","menubar","productivity","screen-lock","sleep-timer","swift"],"created_at":"2026-06-03T16:00:24.906Z","updated_at":"2026-06-03T16:00:38.441Z","avatar_url":"https://github.com/ddasy.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# 🌙 SleepBar\n\n**A lightweight macOS menu bar timer that locks, dims, or sleeps your Mac after a countdown.**\n\n*Set a screen-off timer before bed — give your Mac one last task and let it auto-lock or sleep when time's up.*\n\n**English** · [简体中文](README.zh-CN.md)\n\n![platform](https://img.shields.io/badge/platform-macOS%2014%2B-blue)\n![language](https://img.shields.io/badge/built%20with-Swift-orange)\n![license](https://img.shields.io/badge/license-MIT-green)\n![cpu](https://img.shields.io/badge/idle%20CPU-0%25-success)\n\n\u003c/div\u003e\n\n---\n\n## What is this?\n\nBefore going to sleep you often want to leave your Mac running for a little longer — until a script finishes, an AI agent completes a task, or a download wraps up. But the macOS **\"turn display off\"** delay is a *fixed* setting: 5 minutes this time, 1 hour the next — and changing it means digging into System Settings every single time.\n\n**SleepBar** moves that control to your menu bar. Click the icon, pick a duration, and your screen stays awake for exactly that long. When the countdown ends, your Mac **automatically locks, turns off the display, or even goes to sleep** — whatever you chose. Your task finishes, and your Mac rests.\n\n\u003e No system settings are modified and no `sudo` is required. The moment the timer ends, everything returns to normal.\n\n## ✨ Features\n\n- ⏱️ **Countdown screen-off** — presets of 5 / 10 / 15 / 30 min, 1 hour, or **any custom duration**. The remaining time ticks live in the menu bar.\n- 🔒 **Lock screen** — lock to the login window when time's up.\n- 🖥️ **Turn off display** — lock *and* power down the display to save energy.\n- 💤 **Sleep** — put the whole Mac to sleep when the timer ends.\n- ♾️ **Keep awake forever (Never)** — one click to keep the screen on indefinitely; great for long tasks, presentations, or watching videos.\n- 🔁 **Timed Lock** — *“lock after **5 min** idle, for the next **2 hours**.”* Two numbers, one sentence: how long of no input triggers a lock, and how long the whole thing runs. SleepBar then auto-locks every time you've been idle that long, re-arming after each unlock, until the time's up. The \"run for\" duration is a fixed countdown — locking or unlocking never resets it. **No permissions required** (reads system idle time only, never intercepts input).\n- 🧠 **Remembers your custom duration** — your last value is saved and pre-filled, so your favorite time is one click away.\n- 🌐 **English / Chinese** — switch the entire menu instantly; follows your system language on first launch.\n- 🪶 **Extremely lightweight** — a single Swift file, zero dependencies, no background service. **~0% CPU when idle.**\n\n## 📸 Screenshots\n\n| Chinese UI | English UI | Counting down |\n|:---:|:---:|:---:|\n| ![SleepBar Chinese menu bar screen-off timer](screenshots/zh.png) | ![SleepBar English menu bar auto lock and sleep timer](screenshots/en.png) | ![SleepBar live countdown in the macOS menu bar](screenshots/countdown.png) |\n\n## 🚀 Installation\n\n### Option 1 — One line (recommended)\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/ddasy/SleepBar/main/install.sh | bash\n```\n\n### Option 2 — Clone, then install\n\n```bash\ngit clone https://github.com/ddasy/SleepBar.git\ncd SleepBar\n./install.sh\n```\n\nThe installer automatically: **checks the Swift toolchain → compiles → installs locally → sets up launch-at-login → starts the app.** The 💤 icon appears in your menu bar right away and **launches automatically on every login**.\n\n\u003e If prompted to install the *Xcode Command Line Tools*, accept it and re-run the script. That's Apple's built-in compiler toolchain — no full Xcode required.\n\n### Option 3 — Download the app (DMG)\n\nGrab the latest `SleepBar-vX.Y.Z.dmg` from the [**Releases**](https://github.com/ddasy/SleepBar/releases) page, open it, and drag **SleepBar.app** into **Applications**. Then click the menu-bar icon → **Launch at Login** to start it automatically every time you log in.\n\n\u003e The DMG is ad-hoc signed but not Apple-notarized, so on first launch you may need to **right-click the app → Open**. (The source-based options above avoid this.)\n\n### Uninstall\n\n```bash\n./uninstall.sh\n```\n\nStops the app, removes launch-at-login, and deletes the binary and preferences.\n\n## 🖱️ Usage\n\nClick the 💤 icon in the menu bar:\n\n| Section | Option | What it does |\n|---|---|---|\n| **Screen Off Timer** | 5 / 10 / 15 / 30 min, 1 hour | Starts a countdown; **click again to cancel** |\n| | Custom… | Enter any number of minutes; **remembered \u0026 pre-filled** next time |\n| | Never | Keep the screen on forever (menu bar shows `∞`) |\n| **When Time's Up** | Lock Screen | Lock only |\n| | Lock \u0026 Turn Off Display | Lock + power down the display |\n| | Lock, Off \u0026 Sleep | Lock + put the Mac to sleep |\n| **Timed Lock** | Timed Lock… | A two-line dialog: **\"Lock after `[N]` min idle\"** and **\"Run for `[M]` min, then stop.\"** Auto-locks every time you're idle that long, until the time's up. **Click again to stop.** Both values are remembered \u0026 pre-filled |\n| **Language** | 中文 / English | Switch the whole menu instantly |\n| **Launch at Login** | toggle | Auto-start when you log in. Shown **only in the packaged app (DMG)**; the `install.sh` build already auto-starts via its LaunchAgent |\n| **Quit** | | Quit SleepBar |\n\n\"When Time's Up\" is a set-once, remembered preference applied at the end of every countdown.\n\n**Timed Lock** is independent of the screen-off timer (they're mutually exclusive — starting one stops the other). Example: at 12:00, choose *lock after 5 min idle* and *run for 120 min*. From 12:00 to 14:00 your Mac locks itself after every 5 minutes of inactivity; unlock, step away again, and it re-locks after another 5 minutes. The 2-hour countdown keeps running regardless of how often you lock or unlock.\n\n## ⚙️ How it works\n\nSleepBar is a friendly menu-bar wrapper around capabilities already built into macOS:\n\n| Feature | Under the hood |\n|---|---|\n| Keep awake / countdown | `caffeinate -dis -t \u003cseconds\u003e` (no `sudo`, auto-expires) |\n| Turn off display | `pmset displaysleepnow` |\n| Sleep | `pmset sleepnow` |\n| Lock screen | `SACLockScreenImmediate` from `login.framework` |\n| Timed Lock — idle detection | `CGEventSource.secondsSinceLastEventType` (read-only system idle time; **no Accessibility permission**) |\n| Timed Lock — re-arm after unlock | `com.apple.screenIsUnlocked` distributed notification (event-driven, zero polling while locked) |\n| Remembered preferences | `UserDefaults` (language / end action / custom duration / lock interval / window) |\n\nBecause it relies on the temporary `caffeinate` mechanism, **it never alters your system energy settings** — the moment the timer ends, your Mac is back to its normal behavior.\n\n## 🔋 Low power by design\n\n- **~0% CPU when idle** — no timer runs unless a countdown is active.\n- During a countdown, a single 1 Hz timer with system-coalesced `tolerance` updates only a short text label — **no per-frame allocations**.\n- **Timed Lock never busy-polls.** Instead of checking input every second, it schedules the next wake-up exactly `interval − current idle` seconds ahead, so it wakes the CPU at most once per interval while you're active — and while the screen is locked it does **zero polling**, simply waiting for the unlock notification. The remaining-time readout is computed only when you open the menu, not on a background tick.\n- Built with `-O` (release optimization); a single binary, no embedded frameworks, no helper processes.\n\n## 🛠️ Build from source (development)\n\n```bash\ngit clone https://github.com/ddasy/SleepBar.git\ncd SleepBar\n./run.sh          # compile and launch; re-run after edits for a hot reload\n```\n\nOr manually:\n\n```bash\nswiftc -O main.swift -o SleepBar -framework AppKit\n./SleepBar\n```\n\nThe whole program is a single `main.swift` (~580 lines of AppKit) with no third-party dependencies.\n\n## 📋 Requirements\n\n- macOS 14 (Sonoma) or later (uses the native `sectionHeader` menu API)\n- Xcode Command Line Tools (`xcode-select --install`; the installer prompts you)\n\n## ❓ FAQ\n\n**Q: \"Lock screen\" uses a private API — is that safe?**\nA: It calls the lock function inside the system's `login.framework` (equivalent to pressing your lock-screen shortcut). It needs no Accessibility permission and sends no data anywhere. If a future major macOS release changes it, open an issue.\n\n**Q: Will it secretly keep my Mac awake?**\nA: No. The screen stays on **only** when you actively pick a duration or \"Never.\" On launch it's idle and fully respects your system settings.\n\n**Q: Does it survive a reboot?**\nA: Yes. The installer sets up a LaunchAgent, so it reappears in the menu bar after you log in.\n\n## 🔎 Topics\n\nA free, open-source **menu bar** utility for macOS: **auto lock screen**, **timed / recurring lock on idle**, **sleep timer**, **display sleep / screen-off timer**, **keep awake**, **prevent sleep**, and a friendly **caffeinate GUI**. A minimal, native **Swift** alternative to Amphetamine, KeepingYouAwake, and Caffeine.\n\nSuggested GitHub topics: `macos` · `menubar` · `menu-bar` · `swift` · `appkit` · `caffeinate` · `sleep-timer` · `screen-lock` · `auto-lock` · `idle-lock` · `keep-awake` · `display-sleep` · `productivity` · `macos-app`\n\n## 📄 License\n\n[MIT](LICENSE) © 2026\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddasy%2Fsleepbar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddasy%2Fsleepbar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddasy%2Fsleepbar/lists"}