Jump to content
Stratocumulus

[SOLVED] Run Python script action

Recommended Posts

Hello,

 

I have a Python script which uploads some files. It outputs a few messages to the console when running. I've added the PATH to its location in .bash_profile and so I can run it from anywhere just by typing the name (I have also removed the .py extension to make that easier).

 

I'd like to be able to run it using an Alfred keyword. I've created a blank workflow, added a keyword input and connected a Run Script action to it. I've selected "Exernal Script" and entered the name. This didn't work, so I modified the "Script File" field to include the full path to the file. This made the actual text contents of the script appear in the window of the Script Action, but the action still doesn't do anything.

 

What am I doing wrong?

 

Thanks.

 

(macOS 10.14.6 BTW)

Share this post


Link to post
1 hour ago, Stratocumulus said:

What am I doing wrong?

 

We can't really tell you why a workflow we've never seen isn't working, especially not with a problem description of "doesn't do anything".

 

Use Alfred's debugger. There's quite likely a useful error message in there. Also bear in mind that Alfred doesn't load your shell configuration files and doesn't share your shell environment. If you script depends on anything configured in your dotfiles, it won't work in Alfred.

 

If you'd like our help, please upload your workflow and script somewhere and post links, so we can have a look for ourselves.

Share this post


Link to post

OK, thank you for the Debugger tip, I had never used that before. It certainly helped.

 

I just had to replace this from the beginning of my script:

#!/usr/bin/env python3

With this:

#!/usr/local/bin/python3.7

Anyway, turns out what I really wanted was the Terminal Command Action anyway, not Run Script.

 

All is well now. Thanks.

Share this post


Link to post
22 hours ago, jbreeden said:

Any idea why `env` doesn't get the job done here?

 

env only runs programs  on PATH, and the entire problem here was that the program isn't on PATH.

 

Alfred doesn't use the same environment as your shell because it isn't run from your shell, so if your program isn't in /bin or /usr/bin, it must be called by its full path, not just its name, from within Alfred (and other Mac apps).

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...