kristoffer Posted March 22, 2013 Posted March 22, 2013 I'm working on a shell script that needs to execute some commands installed with homebrew. It's not working, because the path is different in the shell Alfred uses. For instance, if I do "which ruby" in my own shell I get a path to the Ruby version I've installed with homebrew, but if I do the same with my script I get "/usr/bin/ruby" which is the system default. How do I get access to the same shell as the default one, the one where homebrew is available? I've tried sourcing .bash_profile but that doesn't help.
bscott Posted March 23, 2013 Posted March 23, 2013 (edited) I had a similar problem with PHP where I wanted to run different MAMP versions. As you have found, the path used by Alfred is not affected by your profile. I ended up copying the built in /usr/bin/php to /usr/bin/php.osx and creating a symlink from /usr/bin/php to whatever PHP version I wanted to run. It was tedious to change the symlink to a different PHP version so I created a workflow to make things easier (PHP Version). An alternative may be to use the full path to the version you want to run. I'd be interested to learn of a more simple way of doing this. Edited March 23, 2013 by bscott
phyllisstein Posted March 25, 2013 Posted March 25, 2013 I'm working on a shell script that needs to execute some commands installed with homebrew. It's not working, because the path is different in the shell Alfred uses. For instance, if I do "which ruby" in my own shell I get a path to the Ruby version I've installed with homebrew, but if I do the same with my script I get "/usr/bin/ruby" which is the system default. How do I get access to the same shell as the default one, the one where homebrew is available? I've tried sourcing .bash_profile but that doesn't help. If you're just running it on your own system, then you can adjust the PATH setting in /etc/launchd.conf to have it seen by GUI apps. touch launchd.conf, then add export PATH /paste/in/your/path/settings. But you shouldn't require a user to do that, so you should probably just invoke Ruby with the full path in your script. (Though I'd also say that you probably shouldn't require a user to install a brew version of Ruby.)
kristoffer Posted March 25, 2013 Author Posted March 25, 2013 If you're just running it on your own system, then you can adjust the PATH setting in /etc/launchd.conf to have it seen by GUI apps. touch launchd.conf, then add export PATH /paste/in/your/path/settings. But you shouldn't require a user to do that, so you should probably just invoke Ruby with the full path in your script. (Though I'd also say that you probably shouldn't require a user to install a brew version of Ruby.) Ruby was just an example I was actually working on a workflow to control the settings of a homebrew package, but it looks like that won't be possible.
phyllisstein Posted March 26, 2013 Posted March 26, 2013 Ruby was just an example I was actually working on a workflow to control the settings of a homebrew package, but it looks like that won't be possible. Gotcha; I assumed you were using a custom version of Ruby to execute your workflow, which I tend to consider bad form. Sorry!
phyllisstein Posted March 26, 2013 Posted March 26, 2013 Oh, I also forgot that there's another trick I read about. Try adding shopt -s expand_aliases at the beginning of your script. I can't remember whether Pedro's Googling or mine turned it up, but that was necessary to get a background-command workflow to source the user's .bash_profile correctly for some reason. kristoffer 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now