Script to announce Tabata intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const os = require("os"); | |
if (os.platform() !== "darwin") { | |
console.error("This script only works with macOS."); | |
process.exit(1); | |
} | |
const { spawn } = require("child_process"); | |
let [time, rest, reps] = process.argv.slice(2); | |
time ||= 20; | |
rest ||= 10; | |
reps ||= 8; | |
let count = 0; | |
const resetCount = () => (count = 0); | |
const say = message => spawn("say", ["-v", "samantha", message]); | |
const run = (t, r, limit) => { | |
say(count === limit - 1 ? `last set` : `go`); | |
if (count < limit - 1) { | |
setTimeout(() => { | |
count = count + 1; | |
say("rest"); | |
setTimeout(() => { | |
run(t, r, limit); | |
}, rest * 1000); | |
}, t * 1000); | |
} else { | |
setTimeout(() => say("done"), t * 1000); | |
resetCount(); | |
} | |
}; | |
run(time, rest, reps); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment