On Mac OSX, how can I link a script file to a terminal so double-clicking on the icon launches Terminal?

I have a python script that I can run in the normal way using Terminal. For example, run Terminal, cd in the directory, then enter. /xxx.py, where xxx.py is the name of the file containing the script.

Now I want to make a desktop icon that launches Terminal and runs the python file when I double-click it. How can I do it? I thought I could create a shell file using cd and the launch command, and then link this shell file to Terminal. But I can not associate it with Terminal.

Someone said to name the shell file with the suffix ".command", but this forces it to run Flash Builder. I do not know where this assistant is installed. I cannot connect the terminal directly because I cannot find it. This is not in / Applications.

+4
source share
1 answer

On the desktop, you create a file with the following contents

#!/bin/bash

python PATH_TO_YOUR_PYTHON_FILE

Then you should make it doable with

chmod u+x FILE_ON_DESKTOP

Alternatively, you can create a symlink to your python file and make it executable.

You can find Terminal in /Applications/Utilities

+1
source

All Articles