简体   繁体   中英

Run python script in terminal

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

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM