commit 6dcdcb0424db0f9bf58a8608495762e81d4463b2
parent fdc5c232d1fbd23d3734090a5924ea0e7b1fb3b1
Author: Jared Tobin <jared@jtobin.io>
Date: Wed, 2 Dec 2026 11:38:51 +0400
pom: play an alert sound on macOS
When a timer runs out on macOS, play the system Ping sound three times
via afplay, in addition to ringing the terminal bell. The sound plays
regardless of terminal or tmux bell settings, which often silence or
intercept the bell.
Diffstat:
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
@@ -5,7 +5,8 @@ A simple pomodoro timer for the terminal, in the spirit of the old
Pomodoros run for 25 minutes, short breaks for 5, and long breaks for
10. The terminal bell rings when a timer runs out, so tmux will flag
-the window if it's in the background.
+the window if it's in the background. On macOS, an alert sound plays
+too, regardless of terminal bell settings.
## Keys
diff --git a/app/Main.hs b/app/Main.hs
@@ -14,11 +14,13 @@ import qualified Brick as B
import qualified Brick.BChan as BC
import qualified Brick.Widgets.Center as C
import Control.Concurrent (forkIO, threadDelay)
-import Control.Monad (forever)
+import Control.Monad (forever, replicateM_, void, when)
import Control.Monad.IO.Class (liftIO)
import Data.List (intersperse)
import GHC.Clock (getMonotonicTime)
import qualified Graphics.Vty as V
+import System.Info (os)
+import qualified System.Process as P
-- timer ----------------------------------------------------------------------
@@ -105,11 +107,18 @@ toggle = do
reset :: B.EventM () State ()
reset = B.modify $ \st -> st { st_timer = Stopped (duration (st_mode st)) }
--- | Ring the terminal bell.
+-- | Ring the terminal bell and, on macOS, play an alert sound thrice.
bell :: B.EventM () State ()
bell = do
vty <- B.getVtyHandle
- liftIO (V.ringTerminalBell (V.outputIface vty))
+ liftIO $ do
+ V.ringTerminalBell (V.outputIface vty)
+ when (os == "darwin") . void . forkIO . replicateM_ 3 $
+ P.readProcessWithExitCode "afplay" [chime] ""
+
+-- | Alert sound, for macOS.
+chime :: FilePath
+chime = "/System/Library/Sounds/Ping.aiff"
-- drawing --------------------------------------------------------------------
diff --git a/pom.cabal b/pom.cabal
@@ -20,4 +20,5 @@ executable pom
build-depends:
base >= 4.11 && < 5
, brick >= 2 && < 3
+ , process >= 1.6 && < 2
, vty >= 6 && < 7