Last active
October 28, 2021 15:42
-
-
Save nemoDreamer/1e800a7e43f85f157fe0ea5c716353fa to your computer and use it in GitHub Desktop.
A constant reminder to sit up straight...
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
*/5 * * * * /<path-to>/bin/node ./<path-to>/sayPosture.js >/dev/null 2>&1 |
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 | |
// cspell:ignore Veena | |
const { exec: execWithCallback } = require("child_process"); | |
const { promisify } = require("util"); | |
const exec = promisify(execWithCallback); | |
// --- config: | |
const VOICES = [ | |
// "Alex", // en_US # Most people recognize me by my voice. | |
"Daniel", // en_GB # Hello, my name is Daniel. I am a British-English voice. | |
// "Fred", // en_US # I sure like being inside this fancy computer | |
"Karen", // en_AU # Hello, my name is Karen. I am an Australian-English voice. | |
"Moira", // en_IE # Hello, my name is Moira. I am an Irish-English voice. | |
"Rishi", // en_IN # Hello, my name is Rishi. I am an Indian-English voice. | |
"Samantha", // en_US # Hello, my name is Samantha. I am an American-English voice. | |
"Tessa", // en_ZA # Hello, my name is Tessa. I am a South African-English voice. | |
"Veena", // en_IN # Hello, my name is Veena. I am an Indian-English voice. | |
// "Victoria", // en_US # Isn't it nice to have a computer that will talk to you? | |
]; | |
const PHRASES = [ | |
"Are you sitting straight?", | |
"Posture!", | |
"Slouching again?", | |
"Straighten up!", | |
"You're slouching again!", | |
]; | |
// --- helpers: | |
const getRandom = (arr) => arr[Math.round(Math.random() * (arr.length - 1))]; | |
const isOffZoom = () => | |
new Promise((resolve, reject) => { | |
/* | |
> lsof -i 4UDP | grep zoom | |
zoom.us 30869 philipblyth 65u IPv4 0xba9851d3ed103735 0t0 UDP syncsketch-mbp.hsd1.ma.comcast.net:53619 | |
zoom.us 30869 philipblyth 66u IPv4 0xba9851d3ed103d15 0t0 UDP syncsketch-mbp.hsd1.ma.comcast.net:57360 | |
zoom.us 30869 philipblyth 67u IPv4 0xba9851d3ed1013f5 0t0 UDP *:51655 | |
zoom.us 30869 philipblyth 76u IPv4 0xba9851d3ed106c15 0t0 UDP *:53042 | |
zoom.us 30869 philipblyth 78u IPv4 0xba9851d3ed1080a5 0t0 UDP *:50107 | |
> lsof -i 4UDP | grep zoom | wc -l | |
5 | |
*/ | |
// NOTE: needs to be full /usr/sbin path to work inside `crontab` :( | |
exec("/usr/sbin/lsof -i 4UDP | grep zoom | wc -l") | |
.then(({ stdout }) => { | |
stdout.trim() === "0" ? resolve() : reject(Error("Zoom is active!\n")); | |
}) | |
.catch((err) => { | |
reject(err); | |
}); | |
}); | |
// --- run! | |
isOffZoom() | |
.then(async () => { | |
const voice = getRandom(VOICES); | |
const phrase = getRandom(PHRASES); | |
// log: | |
process.stdout.write(`${voice}: "${phrase}"\n`); | |
// say: | |
await exec(`say -v ${voice} "${phrase}"`); | |
}) | |
.catch((err) => { | |
process.stderr.write(err.message); | |
process.stdout.write("Silencing.\n"); | |
}) | |
.finally(() => { | |
process.stdout.write("Done! 👍\n"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sadly, the
env
available to crontab is very limited, so you can't simply rely on the#!/usr/bin/env node
line, but instead need the full path tonode
, even thoughcron
runs as the current user...