GUI Shell Script Mac OS X - Working Directory

Hi.

I'm pretty new to shell scripting. All I want to do is have a simple shell script that opens a python script from the GUI i.e. when I double click the shell script it will launch the python file. However when I try to do this it looks for the python file in my home directory, I have tried changing the directory in the script but it doesn't work.

The idea behind it is so that I can double click a file rather than having to go to the command line each time and tunnel down to the correct directory but at the same time I'm able to run diagnostics on the program I'm working on.

Is all this wishful thinking? Or can it be done? I thought it would be such a simple problem.

Use Automator on Mac OS X. Create a new application not a workflow.

In Automator under utilities add a run shell script action and underneath it add a run applescript if you want to see your output.

Change the interpreter in the shell script to /usr/bin/python and the input drip down should be set to input as args in the drop down in case you want to drop files on it or open files with your "app".

Type your script in the text box. It should have an example like this already:

import sys

for f in sys.argv[1:]:
	print f

Change it by adding this line anywhere for testing purposes:

print "Hello from the shell"

In the applescript action below your shell script action in the applescript action text box there will be an example script like this:

on run {input, parameters}
	
        (*Your script goes here*)

	return input

end run

Change the return input statement to this:

on run {input, parameters}
	
	return display dialog item 1 of input buttons {"OK"} default button 1
	
end run

Click the run triangle to test it. You should get a dialog box with an OK button. Click OK. Save the app where ever you want with what ever name you want. Close Automater and double click the app. You should see you dialog.

If everything is working you can now go back into automater and open the app using the open existing workflow from the dialog that pops up or from the file open menu in Automator.

Edit and play to your hearts content. You only need the applescript action if you need to see the results. Like showing the long listing of a directory or some such.

If you are feeling mischievous you can do a show contents on your newly created app and edit the scripts directly.

If you prefer the console you can browse the directory structure of the app you just created in your favorite text editor or by navigating in a terminal window and using cat or less or lynx or links or mc or some such.