How to replace launchd scheduling with a Python program
The Mac OS X system startup program launchd enables job scheduling (similar to cron.) By creating a launchd agent, one can trigger programs through one of the followin开发者_如何学Pythong events:
- an interval of time has elapsed
- a certain calendar date has come
- a file path has been modified
- something has been placed in a certain directory (queue directory)
- a volume has been mounted
I have previously relied on launchd to start a collection of Python scripts for automating an OS X system. However, since adding a new script also often requires the installation of a new launchd agent for starting it, I would like take launchd out of the equation. A Python program should wait and watch for events like those above to occur, then dispatch the appropriate routine.
Is there a Python module which is appropriate for detecting events like those above? Or, as a more general question, how can I replace launchd in this setting using Python (and possibly AppleScript via the AppScript bridge)? Sorry if the question is rather vague. Reading suggestions are also appreciated.
For the filesystem-monitoring problem, perhaps you are looking for pyfsevents. According to this post,
FSEvents API notifies your application when changes occur in the file system. You can use file system events to monitor directories for any changes, such as the creation, modification, or removal of contained files and directories.
精彩评论