Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support arbitrary script execution during countdown #44

Closed
pigmonkey opened this issue May 25, 2019 · 3 comments

Comments

@pigmonkey
Copy link

commented May 25, 2019

I would like the ability to play sounds at certain intervals during the countdown. Basically, I like the --voice option, but rather than actually calling voice_cmd I want to specify a different program.

I think the most flexible way to achieve this is to add a new argument to termdown that accepts the path to an executable script. During each iteration of the countdown loop, termdown can call this script and pass it seconds_left as an argument.

So executing termdown would look something like:

$ termdown -x ~/bin/foo.sh 60

Which will have the effect of termdown doing its normal 60 second countdown, plus on each second executing:

~/bin/foo.sh 60
~/bin/foo.sh 59
~/bin/foo.sh 58
~/bin/foo.sh 57
...

If I wanted to reimplement the current --voice behaviour, my ~/bin/foo.sh would look like:

#!/bin/bash
case $1 in
    5|10|20|30|60)
        espeak "$1 seconds"
        ;;
    300|600|1800)
        min=$(($1/60))
        espeak "$min minutes"
        ;;
esac

More realistically, I want a 10 minute timer that gives me a 60 second and 10 second audible warning that is more pleasant than espeak's voice. So my script would be:

#!/bin/bash
case $1 in
    60)
        mpv ~/path/to/bell.mp3
        ;;
    10)
        mpv ~/path/to/klaxon.mp3
        ;;
esac

It might be nice if termdown also informed the script if seconds_left <= critical, similar to how the voice support currently works.

Maybe it would be cleaner if termdown provided this information to the script as environment variables rather than as positional arguments? Such that termdown is executing:

SECONDS_LEFT=12 IS_CRITICAL=false ~/bin/foo.sh
SECONDS_LEFT=11 IS_CRITICAL=false ~/bin/foo.sh
SECONDS_LEFT=10 IS_CRITICAL=true ~/bin/foo.sh
...

This would also solve #42.

@Charon77

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

Here's my attempt to this
#45

Example usage:
python3 termdown.py --exec-shell "espeak -v en-us" 10

the current second is put as the last positional argument, so the above would result to:

espeak -v en-us 10
espeak -v en-us 9
espeak -v en-us 8

@pigmonkey

This comment has been minimized.

Copy link
Author

commented Jun 5, 2019

Yup, that's pretty much how I imagined it!

I think the only advantage to using environment variables is that, in the future, more context (like the critical seconds, or the value of some new flag that termdown was called with) can be passed to existing external scripts without breaking them. If those scripts depend on positional arguments, and termdown later changes the number or position of arguments it passes, it could break things for users.

@pigmonkey

This comment has been minimized.

Copy link
Author

commented Jun 17, 2019

I've been using #45 for a bit now. It satisfies my use case, and I think greatly extends the capability of termdown. Is there any chance of getting something like this merged?

@trehn trehn closed this in #45 Jun 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.