Skip to content

Instantly share code, notes, and snippets.

@brandonpittman
Last active June 15, 2021 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonpittman/82f82e1aa2c3e62a0bedf61904f4a2b8 to your computer and use it in GitHub Desktop.
Save brandonpittman/82f82e1aa2c3e62a0bedf61904f4a2b8 to your computer and use it in GitHub Desktop.
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