tags:

views:

555

answers:

3

Hi everyone, I created a script that will tell me what to wear in the morning based on the weather (ie rain slicker if it will rain, heavy jacket if it will be cold, etc). I have fairly basic programming experience with python and the script works perfectly, but I want to be able to create a file that I can just double-click from my desktop and the script will automatically run.

My goal is to be able to simply double click [something] in the morning and it will automatically run the script and thus tell me what to wear. How could I go about doing this?

I am running python on Mac OSX

Thanks!

A: 

What you want to do is create an executable file.

I've never used a Mac or Python, but look at this question and the first answer:

http://stackoverflow.com/questions/2933/an-executable-python-app

Seems http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html is what you're looking for

Baddie
A: 

You want the script to download the weather information online and output the clothes based on your predefined rules?

If this is the case, use urllib to download the page and do some ad hoc parsing over the downloaded html page to get the whether information. And write your logic using nested IF THEN ELSE blocks.

Yin Zhu
Reading the question, I believe that the script works. The OP simply wants to create an icon on his desktop that he can double click and have the script run.
Nikwin
+3  A: 

This worked for me on Snow Leopard:

-Put the python script on the desktop.

-Right click on the script file, and choose "Get info"

-Find "Open With", and choose "Python Launcher" from the dropdown box

Now double-clicking the script file will run the script in a new terminal window.

I'm not sure what versions of OS X come with the Python Launcher application. If you don't have that, you can solve it with a couple extra steps:

-Put the python script anywhere

-Create a shell script on the desktop with one line:

python "/Users/john/scripts/what-to-wear.py"

(Where I've assumed your script is called what-to-wear.py and is in /Users/john/scripts. Be aware that you do need to use an absolute path.)

-Make the shell script executable. In a terminal:

chmod 755 what-to-wear-shell-script

-Double clicking the shell script should run it in a terminal, running your python script.

RJC