How do you make a script or app to run or stop running automatically when the system is booted, a user logs on, at a specific time, when a disk is attached, etc.?
|
Gui MethodIf you want something to run when a user logs in, the easiest way is to use the GUI. You can
Launchd methodIf you want to launch something that is not a
then you want to use the technical solution that is The easiest way to set up a Hand CodingIf you don't want to use Lingon or the PList Website and only want to use the raw tools available on the system, you can write your own Here is my launchd script to run SomeApp continuously after the system boots (independent of a user logging in). It is in /System/Library/LaunchAgents/ and called SomeApp.restart.plist. If it is run based on a user login, it could be stored in ~/Library/LaunchAgents/
Load it once with
There are many additional options that can be found by experimenting with Lingon or by reading the man pages for |
||||
|
|
Lingon still works. I just used it last week to create a "scheduled task". After I downloaded it I had to use its auto-updater to get the latest version but it works fine. |
|||||||||
|
|
If it's only necessary to run when the system is booted, just use the Login Items tab of your Accounts preference pane in System preferences.
If it's a script, use AppleScript Editor to save it as an application. If it's not an AppleScript script, you can still use AppleScript to run the script like this:
|
||||
|
|
|
Don't forget Loginhooks. Although they run as root, you ought to be able to have it execute a $HOME/.loginhook script using something like this:
Then just add whatever commands you want to the ~/.loginhook Also, although 'launchd' is "the Mac way" crontab is still a perfectly viable option, and is much much easier to hand-edit than XML launchd files. Personally, I happily paid $5 for Lingon. |
|||||
|

