0

I have created this python script called 'SleepCalc.py'. It is a simple script that tells me when to wake up based on 90 minute sleep cycles. Usually I open terminal, cd command my way to the dir containing the .py and then execute the script with the 'python' command.

What I want to know is how can I make an app/automator workflow/apple script that I can double click and it executes the python script in the terminal without me having to cd, etc.

http://codebin.org/view/98c0b7c5

2 Answers 2

4

Add shebang: #!/usr/bin/env python at the top of your script.

And then give the file permission to execute by:

chmod +x SleepCalc.py
Sign up to request clarification or add additional context in comments.

1 Comment

Then how do I 'run' it? I double click it and it opens in Xcode. I try to open with > terminal but terminal isn't an option.
0

You open Terminal and enter nano at the top. It opens up a Terminal-based text editor.

After that, type python followed by the file path (at the beginning, include ~/ because the computer starts at the root).

Do Control-X, click Yes, and save it as launch.command.

After that, type chmod +x and drag the newly created file into the Terminal window. This gives permission for the file to execute.

From then on, you can double click the .command file to launch SleepCalc.py.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.