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 |1 Answer
Reset to default 1I 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
版权声明:本文标题:How to pass multiple inputs to a Python script in macOS Shortcuts? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741281673a2370044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
sys.argv
to get parameters and later runscript.py value1 value2 ...
. OR you can usevalue1 = input()
value2 = input()
and script will ask for data - and I think it can work when you send datato stdin
– furas Commented Feb 24 at 19:53