pythonmacosshortcut

How to pass multiple inputs to a Python script in macOS Shortcuts?


I’ve been using a Python script to perform multiple find/replace actions at once. It that has 3 inputs right inside the code, in a form like this:

def main():

text_passage = """
(Here be huge blocks of text)
“""

 to_replace_input = “""
(Here be large strings to look for, each on a new line)
“””

replacements_input = """
(Here be the corresponding replacements, each on a new line)
“””

I’ve just been copy/pasting the 3 of these things right into the code of the script, saving, and running the script. It works fine, but I would like make the experience feel a little bit cleaner/faster with some simple UI elements. And since I already use macOS Shortcuts for many quick tools, I was hoping I could make a Shortcut for this.

But I can’t figure out how to pass three different Shortcut inputs to the script. I’m using 3 of the ASK FOR INPUT actions and one RUN SHELL SCRIPT action.

I tried using ChatGPT to modify the Python script for me to use in this way, but I am getting constant errors relating to input not being passed to the script.

enter image description here

Is there some special way I need to get all 3 inputs communicating to the RUN SHELL SCRIPT action?

I should note that I am not a programmer or anything so it’s also possible I’ve just screwed up the Python script and don’t know what I’m doing. The original method I mentioned still works so this isn’t life or death but it would be nice to understand better and get this working as a Shortcut. Thanks!


Solution

  • I found How to pass variables into shell script : r/shortcuts and there is screenshot which suggests that you can put variables in script and it will copy/paste values automatically:

    Image from answer on Reddit (author: Infamous_Pea6200):

    RUN SHELL SCRIPT on MacOS