Random responses with aText

If you're using Mac's software aText for text expansion you will probably like this little snippet.

You have to create it as a Shell Script and it allows you to print a random message every time you expand it.

#!/bin/sh # Keep this updated when you add or take away quotes on the case list num_greetings=4 # Generate a random quote number variable, 'rand' rand=$[ ( $RANDOM % $num_greetings ) + 1 ] case $rand in #BEGIN CASE 1) greeting="Hello, how may I help you?";; 2) greeting="Hi, how can I help you?";; 3) greeting="Hello, how can I help you?";; 4) greeting="Hello, what can I do for you?";; esac # END CASE # Display the random quote from case statement, and format it to line wrap at 80 characters echo $greeting
Code language: PHP (php)

About Ricard Torres

Senior Front-end Software Engineer at Netcentric, from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

  • Hi Ricard, thank for your code.
    I tryed it and received this: The system cannot find the file specified
    Could you help me?
    Rodrigo Ferreira

    • Hey Rodrigo,

      I don’t know, you should probably ask the developer of the app. Here’s a screenshot of my snippet, make sure to select “content Shell Script”

      Hope this helps!

      A Text

Leave a Reply

Add <code> Some Code </code> if you need to.