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.

 

About

These posts showcase some excellent examples of why Keyboard Maestro is a must-have for every Mac OS user. As a powerful automation tool, Keyboard Maestro helps boost productivity, save time, and streamline repetitive tasks. With its vast array of customizable features and functions, it's the perfect choice for Mac OS users seeking to optimize their workflow.

Schedule

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