Skip to content

Instantly share code, notes, and snippets.

@rmtbb
Created May 2, 2024 02:08
Show Gist options
  • Save rmtbb/853df767f28588462f17adcc2d437a81 to your computer and use it in GitHub Desktop.
Save rmtbb/853df767f28588462f17adcc2d437a81 to your computer and use it in GitHub Desktop.
nohup zsh -c 'while true; do voice=$(say -v "?" | awk "{print \$1}" | sort -R | head -1); say -v "$voice" "It is now $(date "+%l %M %p")."; sleep $((30 + RANDOM % 1971)); done' &
@rmtbb
Copy link
Author

rmtbb commented May 2, 2024

Time Announcement Prank: Announce the time at random intervals and voices.

to use Time Announcement Prank via Terminal:

nohup zsh -c 'while true; do voice=$(say -v "?" | awk "{print \$1}" | sort -R | head -1); say -v "$voice" "It is now $(date "+%l %M %p")."; sleep $((30 + RANDOM % 1971)); done' &

to use Time Announcement Prank via curl:

curl -s https://gist.githubusercontent.com/rmtbb/853df767f28588462f17adcc2d437a81/raw/719ad7e76bdc888c86e8e05b2819bea69dddab78/macTimeAnnouncementPrank.sh | bash

Explanation of the Script

This prank command is designed to run a continuous loop in the background of a Unix-like operating system that periodically uses the say command to audibly announce the current time with a randomly selected voice. Here’s a breakdown of each component:

  1. nohup:

    • nohup stands for "no hang up." It's used to run a command immune to hangups, with output to a non-tty. This means the command will continue running even if the user logs out or the terminal is closed.
  2. zsh -c:

    • This tells the system to execute the following command string ('...') using the Z shell (zsh). The -c option allows passing a command as a string.
  3. while true; do ... done:

    • This is an infinite loop. It uses while true, which means the loop will continue indefinitely because true always evaluates as true.
  4. voice=$(say -v "?" | awk "{print \$1}" | sort -R | head -1);:

    • say -v "?": This command lists all available voices for the say command.
    • awk "{print \$1}": This uses awk, a pattern scanning and processing language, to print the first column of the output, which corresponds to the voice names.
    • sort -R: Randomly shuffles the list of voices.
    • head -1: Selects the first entry from the shuffled list, which will be the random voice chosen for that iteration.
    • The entire output of this pipeline is stored in the variable voice.
  5. say -v "$voice" "It is now $(date "+%l %M %p").";:

    • This command uses the say command to speak out loud. It uses the voice stored in voice to announce the current time.
    • $(date "+%l %M %p"): This command is substituted with the current time, formatted to show the hour (%l), minute (%M), and AM/PM indicator (%p).
  6. sleep $((30 + RANDOM % 1971));:

    • This tells the script to pause for a certain number of seconds before the next iteration of the loop.
    • 30 + RANDOM % 1971 calculates a random delay time where RANDOM % 1971 produces a random number between 0 and 1970, which, when added to 30, results in a delay ranging from 30 seconds to 2000 seconds (or approximately 33 minutes).
  7. &:

    • This symbol is used to put the command into the background, allowing the terminal to be used for other tasks while the command runs indefinitely.

Overall Function

This script continuously announces the time at random intervals using different voices available on the system. It's a practical demonstration of various shell scripting components like loops, random number generation, background execution, and command chaining.

The Antidote: Shut Your Computer Up

to use The Antidote via terminal:

nohup bash -c "ps aux | grep '[s]ay' | awk '{print \$2}' | xargs kill" &

to use The Antidote via curl:

curl -s https://gist.githubusercontent.com/rmtbb/3da43e9f5b03392dbe5d74e09a43f556/raw/38359290144829a7276824a96a778329e3607487/macNumbersPrankAntidote.sh | bash

More Info on the Antidote

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment