Execute a Python Script with Clipboard Contents (Downloading MP3 Audio File for Language Learning)

I am using Keyboard Maestro macros to help in language learning. I was inspired by this post. I created a macro that takes a highlighted word or phrase and translates it to English. It executes a shell script to perform the translation. See below:


I am learning Korean. I have a Python script that takes text input, searches the Naver Korean dictionary online, and downloads an MP3 file of the word if available. I found the script on this post on Reddit and it works well. I can run the script in Terminal and then copy a word or multiple words into a prompt and the MP3 files are saved into the same directory as the script.

I would like to create a KM macro that does the following:

  1. Take a highlighted word and copy it to the clipboard;
  2. Run the Python script (naver.py), paste the clipboard word into the script's prompt, and then hit return

I don't have much experience with shell scripts. Anyone out there to point me in the right direction? I have written the shell script to cd into the directory that I have stored the Python script, and then execute the Python script. I am not sure how to then paste the clipboard contents into the prompt.

cd /Users/matt/OneDrive/Documents/03\ Education/Matt/Language\ Study/Korean/Anki\ Decks/Naver\ Audio\ Files/
python3 naver.py

1 Like