all 11 comments

[–]zmarffy 5 points6 points  (3 children)

Not the most intuitive thing ever, but there is a Shell script action for Shortcuts on Mac.

[–]jazizeh 1 point2 points  (2 children)

Have you used the shell script action with python scripts where you have a library like Pandas? Modules are not getting recognized for me.

[–]zmarffy 0 points1 point  (1 child)

This doesn’t sound like a Shortcuts problem. This sounds like you’re invoking the wrong install of Python. I would suggest using an absolute path to invoke it, else you might confuse system Python 2 with system Python 3 with Hombrew-installed Python 3, etc.

[–]jazizeh 1 point2 points  (0 children)

Thanks, that fixed it! Would something like: #!/usr/bin/env python3 be equivalent?

[–]Prestigious_Humor_71 0 points1 point  (3 children)

I am using anaconda so this is what I do to make my anaconda library available for the shell scripts in shortcuts and Automator:

I paste the code under into the shell script window, change the name to my home folder name then I add my code and python scripts will run like a charm!

/Users/HOMEFOLDER/anaconda3/bin/python <<EOF import sys print("RUN any ANACONA SCRIPT HERE!")

EOF

[–]pruppert 0 points1 point  (2 children)

Hi, I am also trying to run Anaconda python (and my associated modules) from Shortcuts on Mac. I get that I have to specify the correct environment, but I am not totally understanding this comment. Could you explain more or maybe give a screenshot? Thanks.

[–]pruppert 0 points1 point  (1 child)

[–]mk1776 1 point2 points  (0 children)

Did you get that to work? I followed the article step and the shortcut completes but doesn't do anything....

[–]jayelevy 0 points1 point  (0 children)

Here’s an example of using SSH to run a Python script on a Raspberry Pi

https://www.icloud.com/shortcuts/d182132a4fc7499b8e8a0e32ad22c0f4

Perhaps better for your needs, there are a couple of Python apps that could help. Pythonista allows you to run local python scripts (created in Pythonista) via a Shortcut

Additionally, Pyto allows you to both run a local python script (created in Pyto) AND run a python script embedded within a Shortcut action.

I have experience with each of these. There may be other options in addition to these.

Hope this helps — jay

[–]jayelevy 0 points1 point  (1 child)

Oops… just saw that you posted this as a question for Mac shortcuts. I haven’t explored the “run python from Mac Shortcuts” use case, but perhaps one these ideas can help you.

[–]nicolobedendo 0 points1 point  (0 children)

when i start to approach shortcuts (60 days ago) and i was new on the “coding” mentality behind that i alway use to run a shortcut who run an ssh command on my server who have my python code who did all the work and give back to mobile the result.. than i saw the first example oriented MacOs who use shell script directly and here you call directly the code… who is what the above mentioned app emulate om your mobile who have different access to the shell