Search code examples
macosshellterminaltext-to-speech

Passing readable punctuated text through ssh commands in macOS?


I need to "say" things to people from the shell and would like to set up an alias that properly and automatically escapes punctuation marks.

I currently have an alias that's working great, except for questions, commas, etc.:

 tell_someone='ssh -e none username@hostname say'

But when I run tell_someone "can you hear me?", it returns:

zsh:1: no matches found: me?

While tell_someone "can you hear me\?" works fine. I'd like to make this work with and without quotes if possible, but I need it to obviously escape the punctuation.

Can a simple alias do the job or do I need to resort to writing a script that will handle this in a more robust manner?

NOTE: my rationale is that everyone I work with wears headphones and have multiple monitors and so it's nearly impossible to get attention so I frequently have to restore to more covert means like we used to do in computer lab in college pranks on Sun systems where we used to play audio at people... :)


Solution

  • Try using this function instead of your alias (don't worry; it feels the same as an alias, it just handles arguments in a more flexible way):

    tell_someone () { printf "%q" "$*" | ssh -x -e none someone@host say }
    

    Adjust it as per your needs.