Jump to content

Problem with PATH


Recommended Posts

Ok, I'm not 100% clear on exactly what the problem is, so I'm going to attempt to describe what happens in a number of related scenarios. Hopefully this will suffice. 
 
In short, I am having a problem when I try to run a CLI-based program (pandoc) from a Python script which is told to run in a Run Script action. 
 
Here's the long version: I have a workflow that calls to a Python script (pandoctor.py) which itself uses the subprocess module to call the pandoc CLI. pandoc (in this instance) is using a dependency (xelatex). Whenever I use the Run Script action, I get the error from pandoc that "pandoc: xelatex not found. xelatex is needed for pdf output." To me, this suggests that

  • the Alfred call to run pandoctor.py runs well
  • the pandoctor.py call to run pandoc runs well
  • but, pandoc's call to xelatex is broken

Now, I believe that this issue revolves around how PATH is handled and passed between script because this same code will work if I just run the pandoctor.py script itself (with the appropriate arguments) and if I open Terminal and run the code that I have in the Run Script action (e.g. `python pandoctory.py run "{query}" (tho of course in Terminal I manually input the query)). 
 
I am assuming that Alfred has a somewhat different environment than the Terminal, with a different PATH, and this is why pandoc cannot find xelatex
 
So, I have questions:

  • is there a difference in Terminal and Alfred's Run Script environment?
  • if so, what exactly is it?
  • how can I fix my workflow to work properly within Alfred's environment?

NOTE: I am on the latest build of Alfred (2.3 264)

Link to comment

This is not specific to Stephen's issue, but applies generally.

 

Alfred (and all OS X apps) completely ignore your shell setup scripts (.bashrc etc.), and therefore environment. All apps are called with launchd's environment (the same applies to LaunchAgents).

 

If you want to call an executable that isn't in /bin or /usr/bin, you should specify the full path (e.g. /usr/local/bin/program).

 

If the executable you call in turn calls something that isn't on launchd's barebone PATH, you need to update PATH before calling it, e.g. (bash):

export PATH=$PATH:/usr/local/bin
program arg1 arg2

A consequence of this is that if you call a Python/Ruby/etc. script via bash in Alfred, you should always specify the full path to the interpreter, e.g.: /usr/bin/python myscript.py or /usr/bin/ruby myscript.rb. If you don't do this, and you have a custom version of Python/Ruby in /usr/local/bin, it's possible that your script will work from Terminal, but not from Alfred, because they're using different Python/Ruby installations, which may behave differently or have different libraries installed.

Edited by deanishe
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...