One of Tiger ’s unappreciated increase is a fresh Unix utility program , launchd , that can mechanically run anything — include applications , AppleScripts , shell scripts , and Automator workflows . Use it to launch a political platform at startup or login , on a fixed or repeating docket , when a filing cabinet changes , or when you add a new file to a folder . It can even embark on a curriculum in answer to connection access on a certain port .

Launchd improve system public presentation by limiting the numeral of background processes that must run all the prison term . It also makes mechanization easier ; this individual tool replaces legion launch utilities , including cron , rc , and guard dog . I ’ll walk you through the process of create two example launchd business : a simple daily backup , and a job that moves file cabinet from your Drop Box leaflet to your screen background . If you get snitch , you’re able to learn more about launchdhere .

Get ready for takeoff

To make a launchd job , you make a preference ( .plist ) filing cabinet listing what you require to set up , as well as when and how . Then you put the file in one of several folders . The booklet you take determines when the occupation loads and whether it runs as the root user or as another user .

When you ’re creating the job , economize yourself some heartache by using Peter Borg ’s freeLingon . This usefulness writes the XML computer code and give you an prosperous way to do steps that would otherwise require a trip to Terminal .

When you open up Lingon , you ’ll see five tab across the program window . These represent the dissimilar folders where you may store launchd jobs .

Article image

•My AgentsThe job list in this pane live in /your drug user folder / Library / LaunchAgents . They stretch when you sign in . habituate this location for any caper that should impress only files within your user folder , or that should go only when you ’re logged in .

•Users AgentsJobs list in this pane are stored in /Library / LaunchAgents . They load whenanyuser logs in , and run as that user . This would be useful when you require a screen background plan to fly the coop for all a machine ’s users but do n’t want to put it in each user ’s Login Items list .

•Users DaemonsJobs listed in this pane reside in /Library / LaunchDaemons . They load when your Mac starts up and they execute as the radical exploiter . This is utilitarian for jobs that need to hunt regardless of which exploiter ( if any ) is logged in , or for jobs that do actions requiring an decision maker password .

•System Agents and System DaemonsJobs list here are stored in /System / Library / LaunchAgents and /System / Library / LaunchDaemons , respectively . Like job in the Users Daemons pane , they stretch at inauguration and run as the root drug user , but because they ’re inside the System brochure , you should not alter them . You may , however , rule it instructive tolookat the System daimon list , which contains all of Tiger ’s preinstalled launchd jobs . Many of these formerly used cron . ( tick herefor more about cron . )

Create a backup job

Say you require to create a job that backs up a Mac ’s Users folder every day . You could use Automator and iCal , but the workflow would skip files not owned by the exploiter currently logged in . Using launchd , you could copy information for all user at the same time and schedule the patronage to occur no matter which user ( if any ) is logged in .

To get down , open Lingon . tap the New button in the toolbar and prime Users Daemons in the sheet that appears . snap on Create , and then enrol your decision maker password . You ’ll move into the rest of your options in the bed sheet that come along .

Name That JobClick on the Basic tabloid and enter a name in the Label champaign . This name must be unparalleled on this calculator or the occupation wo n’t load . Apple recommends this designation pattern : com.macworld . DailyBackup . The first two parts of the name should look like a slow-witted knowledge domain name . ( you could use your actual domain name , make one up , or usecom.your_short_user_name;this pattern only makes sure that two people do n’t add up up with the same name . ) Lingon automatically adds the.plistextension when it save the single file .

Opening ArgumentsThe complimentary Lingon utility makes creating a launchd job much easier . Enter the path of the programme you want to run and any contention in the ProgramArguments section . Each argumentation or flagstone run on a separate line . ( Click picture to open full screenshot )

Pick Your TargetClick on the positive - sign ( + ) push button next to the ProgramArguments field and figure thefullpath for the program you require to launch . In this example , you ’re go away to consort a Unix command . These often useflagsto set options andargumentsto pin down which files or folders to act on . When typecast them into Lingon , you must enter each of these particular ( normally part by space ) on a separate business ( see screenshot ) .

The command you want to lam is

The rsync course of study is located in the /usr / bin directory , so after you tap the plus - planetary house button , double - click in the text field and eccentric

The argument

Note that for a launchd job that launches a steady practical program instead of a Unix bid , you need the track not just to the program , but to the single file that contains the feasible code inside its package . For example , the track for iTunes would be

Make It RunYou’ve indicatedwhatwill launch ; the next ( and trickiest ) step is to definewhenit will launch . Lingon offer many options ( seeLaunch Timefor details ) . For this illustration , select just two .

In the canonic pane , pick out the OnDemand choice . leave alone the other options here deselected . ( If you selected the RunAtLoad option , your job would run instantly ; in this case , you want to specify a time . )

tap the Miscellaneous tab . In the StartCalendarInterval text edition field , type

laden It UpClick on the Save & Load push button to store your launchd job and load it into memory . ( If you fall into place on the Just Save button , your job will load mechanically on your next restart or login . )

To temporarily disable a blotto job , tap the correct folder tab ( for representative , My Agents ) , find the caper , and get through on the Unload push . To load it again , tick on Load . To disable a job for good without delete it , press Edit , press the Basic tab , and then take the handicapped selection .

Spring-load your drop box

Now that you have a feel for how to create launchd jobs , let ’s try something dissimilar : a job that forthwith moves anything placed in your Drop Box folder ( /your drug user folder / Public / Drop Box ) to your screen background . That way , when another user on your mesh sends you a Indian file , you wo n’t have to compass for it .

First , use your favourite text editor — for example , Bare Bones Software ’s freeTextWrangler — to create a mere script :

Name the playscript DropBox and economise it ( ordownload it ) . Open Terminal ( /Applications / Utilities ) , type the command

Still in the Basic tab , sink in on the positive - augury button next to ProgramArguments . Double - select the first line of the text edition field ; then drag your DropBox script file from the Finder onto the first communication channel of the ProgramArguments field to enter its name and path . pick out the OnDemand pick .

penetrate on the Paths tab . select the positive - sign button next to WatchPaths , forked - click in the field , and enter

select Save & Load . To quiz the job , move any Indian file into your Drop Box folder . The file should straightaway disappear — and reappear on your desktop .

Troubleshoot your job

Code is picky , finical , finical ! A stray space , wrong capitalization , or a literal error can slump your task . If a launchd business does n’t work correctly , tap Unload to call on it off . threefold - check into your script ( if there is one ) by lam it manually in Terminal . Then equate your job ’s .plist contents , in Lingon ’s Expert acid , with these screenshots . If everything matches , go to the Basic Elvis , ensure that the handicapped choice is not selected , and select Just Save . press Reload to recharge the job .

[ Joe Kissell has written legion eastward - account book aboutMac OS disco biscuit software . ]