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

asked Jun 5, 2014 at 6:28

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
answered Jun 5, 2014 at 6:32
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.

Shawn Mehan
4,60810 gold badges33 silver badges51 bronze badges
answered Nov 18, 2015 at 22:33

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.