Skip to content
Advertisement

How can I combine the commands leave and say?

Is there a way to make use of the command leave and the command say (MacOS) to be notified by the built in voice system?

I can do echo hello | say on the command line.

leave outputs Time to leave! how can this output be piped to say once it appears?

When I issue this command it’s just hanging. (no leave process is created)

JavaScript

man leave

JavaScript

Thank you!

Advertisement

Answer

It sounds like leave writes one line of output per day. If say is trying to read all of stdin at a go (or otherwise do any kind of a read that is not one-character-at-a-time stopping at the first newline), the buffer will never be full enough for its read to complete in a reasonable time period.

The bash read builtin does these (inefficient) one-character-at-a-time reads, and so is able to get content from a pipeline more appropriately (as long as leave is overriding libc’s default buffering behavior, which switches from line-buffered to fully-buffered when output is not direct to a TTY; but if it doesn’t do this, that’s a bug you should report to your OS vendor).


To run a new copy of say for each line of output from leave:

JavaScript

To wait until leave has some output, run say exactly once, then exit:

JavaScript

All of this can be put in the background if you choose. For example:

JavaScript

…will do an equivalent of running the above code in the background with nohup, writing any errors to leave-say.log instead of nohup.out.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement