Jump to content

How to run script from /usr/local/bin?


Recommended Posts

Hi everyone!

 

For long, I've been launching VirtualBox's virtual machines with the following script, bin/bash being the language selected:

VBoxManage startvm "vm_name"

In a recent update, it seems that VirtualBox moved the necessary "files" (I don't really know/understand what happens in the background) from /usr/bin to /usr/local/bin. See this topic: https://forums.virtualbox.org/viewtopic.php?f=8&t=68825. People there pointed that it might be related to recent security restrictions in OS X (Yosemite, El Capitan).

 

From the Terminal, when I first point to /usr/local/bin, the previous piece of code works perfectly. So my question is, how can I point to that special directory from a Run script window of a workflow?

 

Ultimately, should Alfred be updated to offer /usr/local/bin in the Language list?

 

Thanks for your help!

Link to comment

/usr/local/bin is not a language (neither is /bin or /usr/bin). They're directories.
 
Your environment has a variable called PATH, which is a list of directories. When a program (or a shell) wants to run another program, it can simply call it by name (e.g. VBoxManage) provided it is in one of the directories in PATH.
 
Alfred's PATH is the default one of /bin and /usr/bin, so any program in either of those directories can be called by name.
 
If you want to run a program in /usr/local/bin, you have to call it by its full path, e.g. /usr/local/bin/VBoxManage.
 
So, instead of running VBoxManage startvm "vm_name" you just need to run:

/usr/local/bin/VBoxManage startvm "vm_name"
Link to comment

 

/usr/local/bin is not a language (neither is /bin or /usr/bin). They're directories.

 

Your environment has a variable called PATH, which is a list of directories. When a program (or a shell) wants to run another program, it can simply call it by name (e.g. VBoxManage) provided it is in one of the directories in PATH.

 

Alfred's PATH is the default one of /bin and /usr/bin, so any program in either of those directories can be called by name.

 

If you want to run a program in /usr/local/bin, you have to call it by its full path, e.g. /usr/local/bin/VBoxManage.

 

So, instead of running VBoxManage startvm "vm_name" you just need to run:

/usr/local/bin/VBoxManage startvm "vm_name"

 

Thank you very much @deanishe for the explanations and the solution you provided, that makes sense and works perfectly!

Link to comment

Just to expand a bit on deanishe’s (as always excellent) answer, in addition to providing the full path to the executable, you may also expand your PATH in your Alfred script.
 
What I mean is: instead of using /usr/local/bin/program_name repeatedly for every one of them, if you know they are all inside /usr/local/bin you may start your script with the line PATH=/usr/local/bin:$PATH (directories in PATH are separated by :, and calling it like in this example means your already existing PATH will be appended to your additions).
 
What this allows you is to call program_name (without the full path), for the continued duration of the script.

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...