• Mac OS X,  Mac OS X Server,  Mac Security

    Mac OS X: Loading and Unloading with launchd

    In Mac OS X you can use cron to schedule tasks but you can also use launchd.  To use launchd to load or unload an agent where you’ve setup a task use the launchctl command.  Here we will use launchctl to manually start a process given that we defined a plist called /Library/LaunchAgents/com.apple.OpenProgram.plist (where program is maybe the name of some program you want to fire up): launchctl load Library/LaunchAgents/com.apple.OpenProgram.plist Your application should fire up now.  Do not quit it for ten seconds. Wait about 15, then quit it. Notice it start up again. This is because it is a launchAgent and will restart any time it is closed.  Now…

  • Mac OS X,  Mac OS X Server

    Creating a LaunchAgent

    If you want to make a program start at a certain time or always run on Mac OS X then you should use launchd. Launchd can start your web, FTP or SMB daemon’s or even an application or open a file. Launchd uses property lists to identify various parameters for the agents you will be creating. Using Property List editor, create a new list and add the following items: Root dictionary Label string ProgramArguments array OnDemand boolean Set if we are going to use TextEdit as an example, then set them like so: Label: com.apple.TextEdit OnDemand: false ProgramArguments: one child, a string: /Applications/TextEdit.app/Contents/MacOS/TextEdit Save this file in ~/Library/LaunchAgents/com.apple.TextEdit.plist or /Library/LaunchAgents/com.apple.TetEdit.plist…