4

I created a script that will tell me what to wear in the morning based on the weather (i.e. 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?

System Specifications:

  • python
  • Mac OSX
Harshdeep Sokhey
  • 324
  • 5
  • 15
John
  • 81
  • 1
  • 1
  • 3

5 Answers5

6

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
  • 94
  • 2
0

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:

How can I create a directly-executable cross-platform GUI app using Python?

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

Community
  • 1
  • 1
Omar
  • 39,496
  • 45
  • 145
  • 213
0

Use a batch file to make it automatic

Example : 1. Open Notepad -> type the following. This one's for Windows..It might give you a hint :start C:\Python34\python.exe(your python file location)Your *.py file location.

:end Save this with a *.bat extension That's it ..you can configure more on this batch,I guess batch is the automation for day to day script

swapnil
  • 9
  • 1
-2

In Linux/unix based OS , add #!/usr/bin/python3 line on top of your script file with extension .py , if you have python version 3. Or change it to the version installed in the machine Further , make the file executable by

sudo chmod +x <fileName>

for windows, add windows python path and make the file executable

G5W
  • 36,531
  • 10
  • 47
  • 80
zOthix
  • 1
-3

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
  • 16,980
  • 13
  • 75
  • 117
  • 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 Dec 06 '09 at 09:32