QA Graphic

Multiple Words List (Python)

Sample Shell Script in Keyboard Maestro

As part of my testing process, I occasionally require a list of words. To facilitate this, I developed a Keyboard Maestro macro that generates a list of 10 random words. Previously, I had crafted a similar script in PHP, but I've recently updated it to Python 3.

While I didn't observe any performance enhancements between the PHP and Python shell scripts, I did notice a quicker display of results when utilizing the 'Paste Results' feature.

KM Multiple Words 2023
Sample Macro

Python Code


#!/usr/bin/python3
import random
# Open the file with read permission
with open("/usr/share/dict/words", "r") as file:
    words = file.readlines()
    words_length = len(words)
def random_word():
    # Choose a random word from the list
    rand_word = random.choice(words).strip()
    # Remove possessive case and capitalize the word
    description = rand_word.replace("'s", "")
    return description.capitalize()
# Generate and print 10 pairs of random words
for _ in range(11):
    print(random_word(), random_word())

One More Thing

You'll notice that I have two different shortcuts assigned to this macro. This is a neat feature of Keyboard Maestro. You can assign multiple shortcuts to perform the same action. Useful when you may know the shortcut as different things in different projects.

Next week, I'll show you a cool way to take advantage of using multiple shortcuts for the same macro.

 

Comments

Add Comments

Name:
Comment:

 

About

These posts highlights some cool examples of why Keyboard Maestro should be part of every Mac OS user's computer. Keyboard Maestro is a powerful automation tool that can help improve productivity, save time, and streamline tedious tasks. It has a wide range of features and functions that can be customized to suit any user's needs, making it an ideal choice for Mac OS users.

Schedule

SaturdayInternet Tools
SundayOpen Topic
Monday Media Monday
TuesdayQA
WednesdayKeyboard Maestro
ThursdayGluten Free
FridayMacintosh