tags:

views:

286

answers:

2

I am working on Mac OS X and I have a Python script which is going to be called by other scripts and programs (Apple's launchd in particular). I could call it with

python /Users/xyz/long/absolute/path/to/script.py arg1 arg2

Since the location of the script might change, I want to decouple other scripts and the launchd configuration files from the actual location, so that a call to the script looks like

script arg1 arg2

Defining an alias for Bash in $HOME/.bash_profile does not work, since launchd does not know about the alias.

What is the best way to define a "sytem-wide alias" or something equivalent?

+4  A: 

I usually make a symbolic link and put it in /usr/bin (assuming /usr/bin is part of your PATH)

(In a terminal. You may have to use sudo ln -s depending on the permissions.

ln -s /Users/xyz/long/absolute/path/to/script.py /usr/bin/script.py

If you take Rory's advice and put the #!/usr/bin/python at the beginning of the script, you'll also need to make the script executable.

chmod a+x /Users/xyz/long/absolute/path/to/script.py
Mark Biek
Good idea. I also put #! /usr/bin/python in the first line to make it executable. But I still get a/usr/bin/script: Permission deniedif I call >scriptWhat am I doing wrong? Do I have to chmod it manually?
D-Bug
Yes, you'll need to do a chmod on it. I edited with an example
Mark Biek
+3  A: 

As well as doing a symlink, you can put "#! /path/to/python" at the start of the script and make it executabe. Then you don't have to call it with "python /Users/big/long/path/script.py"

Rory
+1: Always put `#!/usr/bin/env python` at the front of every script.
S.Lott