Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

I Want to make a shortcut to a terminal command

I have a python script that I run in terminal but inorder to launch it I have to type:


~/Documents/python\ stuff


and then


python apps.py


I want to make a shortsut or app so I dont have to do that every time.



Thanks.

MacBook Pro, OS X Mountain Lion (10.8.2)

Posted on Dec 28, 2012 4:32 PM

Reply
5 replies

Dec 28, 2012 6:34 PM in response to Col1107

Do you


cd ~/Documents/python\ stuff


or is


~/Documents/python\ stuff


a program/script that you run first?


Can you enter:


python ~/Documents/python\ stuff/apps.py


Anyway, if you create a ~/.bash_profile shell initialization script, you can create any number of ways to run the python script.


nano ~/.bash_profile


will allow you to edit the shell initialization script.


Things you can create


myCommandName()
{
    (  cd ~/Documents/python\ stuff
       python apps.py

       #
       # or whatever commands you need to execute.
       #
    )
}


Save the .bash_profile, and restart you Terminal session so the .bash_profile shell initialization script is run as your shell startup in a new Terminal session.


if "python ~/Documents/python\ stuff/apps.py" works, then you could use


alias myCommandName "python ~/Documents/python\ stuff/apps.py"


again restart you Terminal session.

Dec 29, 2012 9:51 AM in response to BobHarris

Thanks for the quick reply, but I'm really not very advanced with terminal so.. I have no idea what you you just said. I was thinking that there may be a way to do it in AppleScripEditor and make an executable program. Is This possible?


Yes I do type:

   cd ~/Documents/python\ stuff   

And

  python ~/Documents/python\ stuff/apps.py

does work.




When I tries to type in


alias apps "python ~/Documents/python\ stuff/python.py"


I get:



-bash: alias: apps: not found
-bash: alias: python ~/Documents/python\ stuff/python.py: not found




Thanks for any help!

Dec 30, 2012 7:19 PM in response to BobHarris

Im sorry I still don't understand. You'll have to talk to me like im 5.


So i go to terminal and i can type


python ~/Documents/python\ stuff/apps.py

and my program runs.


And then I type in


alias apps="python '~/Documents/python\ stuff/apps.py' "

and I get a new terminal command. I restart my terminal session.


Then what? If I type is "apps" I get:

-bash: apps: command not found


If I dont restart my terminal session After typing in the alias thing, I get:


/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file '~/Documents/python\ stuff/apps.py': [Errno 2] No such file or directory



Thanks again! Im sorry I don't understand.

Dec 30, 2012 8:01 PM in response to Col1107

I restart my terminal session.


Then what? If I type is "apps" I get:

-bash: apps: command not found

The 'alias' command only lives in the current session. if you start a new Terminal session or Window, then you have a new session.


If you wish to have your 'alias' everytime you start a Terminal session or window, then you need to put the 'alias' command in a shell initialization file:


nano ~/.bash_profile


and add the 'alias' command here. Now everytime you start Terminal or a new Terminal window, the .bash_profile will be run, and your 'alias' will be defined.


Message was edited by: BobHarris

I Want to make a shortcut to a terminal command

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.