admin管理员组

文章数量:1279220

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.

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!

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.

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!

Share Improve this question asked Feb 24 at 9:49 Crabgrass0899Crabgrass0899 2801 silver badge13 bronze badges 3
  • I don't have Mac and I don't know how works shortcut but usually when you run script in console then you can use sys.argv to get parameters and later run script.py value1 value2 .... OR you can use value1 = input() value2 = input() and script will ask for data - and I think it can work when you send data to stdin – furas Commented Feb 24 at 19:53
  • 1 I found How to pass variables into shell script : r/shortcuts and there is screenshot which suggest that you can put variables in script and it will copy/paste values automatically. – furas Commented Feb 24 at 19:57
  • 1 Ah, I had no idea you could right-click inside the script code itself and insert Shortcut variables that way! It worked. If you want to write your comment as a real answer to this question, I am happy to select your contribution as THE answer. – Crabgrass0899 Commented Feb 25 at 3:40
Add a comment  | 

1 Answer 1

Reset to default 1

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):

本文标签: How to pass multiple inputs to a Python script in macOS ShortcutsStack Overflow