[Tutor] Running a script in the background
William R. Wing (Bill Wing)
wrw at mac.com
Sun Sep 2 22:30:13 CEST 2012
On Sep 1, 2012, at 11:29 PM, Michael Lewis <mjolewis at gmail.com> wrote:
> Hi everyone,
> I am sorry to ask this when there are a lot of resources online regarding the subject, but I've spent the past two days trying to figure this out and I don't get it.
> I have a script that will run forever. Since it runs forever, I don't want to see the interpreter or command line. I want the program to run in the background so I don't see it at all.
> How can I do this? For some background, my script essentially check every x minutes to see if any files have been updated and then moves them to dropbox.
> I want to be able to do this on both OSX Mountain Lion and Windows 7. If need be, I can create two separate scripts to separate out the two OS's.
> Michael J. Lewis
Michael, I see you have several Windows answers, but it doesn't look as though you found quite what you were hoping for on OSX. My suggestion would be to take the script and run it through py2app, which will turn it into a stand-alone application which can then be added to your list of StartUp or LogIn applications. If you never request input or produce output, it will quite happily run in the background with no window and no menu (although by default there will be an icon in the dock). At that point it is so much a background application that the ONLY way you can quit it is via the Force Quit dialog. If you generate status or housekeeping print messages, they will show up in ~/Library/Logfiles. Py2app isn't particularly memory efficient, even a minimal application tends to run close to 9-10 Mbytes, but if it spends most of its time sleeping, it will use very little in the way of system resources.
If you want it to run even when you aren't logged in, you will have to go to a bit more trouble. You will have to make up an installer plist file and use launchctl to add it to the list of stuff under control of the launchd daemon.
More information about the Tutor