Skip to content

Instantly share code, notes, and snippets.

@brandonpittman
Last active Jun 15, 2021
Embed
What would you like to do?
Script to announce Tabata intervals
#!/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