Creating a .command file
Hello! I would like to know how can I create the equivalent of a "batch" file from windows in OSX.
I want it to run 2 simple commands:
1. cd to a specific folder
2. run a python command.
Thanks!
Hello! I would like to know how can I create the equivalent of a "batch" file from windows in OSX.
I want it to run 2 simple commands:
1. cd to a specific folder
2. run a python command.
Thanks!
Open a text editor like TextEdit and type in your commands:
cd /path_name/folder_name
run python command
Save the file as my_command_name.command where the extent really is ".command" rather than the default of ".txt".
Are you expecting a reply? You have given me nothing with which to help.
As I mentioned, the .command file is a script, and to run it, you must make it executable.
Rock.command contents:
#!/bin/bash
# assumption that runserver.py is in the Rock folder
cd ~/Desktop/Rock
python runserver.py
Not working
A .command file must be made executable before it is run. You do this in the Terminal, and in this instance, you are making it executable strictly for you:
chmod +x my.command
Now, providing the contents have been tested interactively beforehand in the Terminal, you can double-click this my.command file in the Finder, and it will pop a Terminal window, run, and then kill the Terminal session without quiting the Terminal window it created.
For your example, you need to make your my.command file a Bash script which will honor your change directory (cd) command in a Bash shell, before running the Python script:
#!/bin/bash
# change directory to /Users/myname/Test
cd ~/Test
# run the Python script located in your home directory
./my.py
If you just wanted to run a Python script in your my.command file, you could replace the Bash invocation line with:
#!/usr/bin/python
# coding: utf-8
I'm sorry I don't know how to adapt what you just said. So basically I have this folder "cd /Users/Bog/Desktop/Rock"and I want this python command to be executed inside the folder "python ./runserver.py". And then the Terminal would take over. That's it!
Doing this manually, I would type cd /Users/Bog/Desktop/Rock in a terminal window, and then run the python command. Having a lot of instances in that folder is really annoying and I would like to have one file to click on it and do the job. TY!
Creating a .command file