Skip to content

OS X Tip: Staggered Login Items

Mac OS X 10.4 Tiger includes a new mechanism called launchd. It's an excellent system, which replaced many separate programs which all accomplished related tasks, like init, mach_init, xinetd, RC, SystemStarter, watchdog, and cron. A good overview is launchd in Depth.

launchd also took over responsibility for launching "Startup Items", or "Login Items", which start when a user logs in. This is an elegant and sensible change. However, there is at least one significant downside: unlike the mechanism in 10.3 Panther and earlier versions of OS X, which launched Login Items one at a time, sequentially, launchd launches every Login Item at the exact same time. This isn't necessarily a downside for everyone; in fact, it may even be better for most people, who probably don't have more than a handful of fairly lightweight Login Items. For people like me, however, who have quite a few Login Items set up, some of which aren't so lightweight, the simultaneous launching of all those programs can tie up my system, making it unresponsive for up to a minute after I login. Maybe I'm inpatient, but when I log in I have things to do - I don't want to wait a minute before I can do them.

A Google search reveals a bunch of solutions to this problem, most of which involve a shell script or an AppleScript or some combination of the two. Tonight, for some reason, I decided to switch over to a staggered launch method. I wasn't sure exactly what approach I would take, until I read Luke Cowell's Get real about startup optimization. He specifically pointed out a performance issue with the AppleScript "tell application X to launch" command.

But while Luke ended up writing a shell script, and an AppleScript to launch that shell script, I thought I could come up with an AppleScript-only approach which would retain the speed and spirit of Luke's approach.

In a nutshell, I came up with this template for my script:

delay 10

do shell script "open '/Path/To/Application 1'"

delay 1
do shell script "open '/Path/To/Application 2'"

delay 1
do shell script "open '/Path/To/Application 3'"

...etc...

In order to get the paths of the programs to launch, I opened up ~/Library/Preferences/loginwindow.plist in a plist editor (I used Pref Setter but Apple's Property List Editor or even defaults read loginwindow would work too) and copied each Item's path into the script. Then I just saved the script as an Application, and, in the Login Items tab of the Accounts preference pane, removed all the existing Items and replaced them with my script.

And it works! My system is now much more responsive from the moment I log in, and I can get to work immediately. I hope Apple addresses this minor shortcoming in launchd at some point, but until then, I'm good.

Comment Feed

5 Responses

  1. what about hiding? i’m not familiar with writing scripts. can i set this launcher to automatically hide the applications it starts up?

  2. Only thing I can think of is something like this:

    do shell script “open ‘/Path/To/Application 2′”
    tell application "System Events" to set visible of process "Application 2" to false
  3. Avi, this worked great for me! Thanks!

  4. that’s phenomenal. so easy. I actually learned how to make scripts for this! I’ve been holding off on the scripts thing cause it daunted me, but the slow login KILLS me. Login is pretty much the one time when I REALLY want my computer to JUMP. Why else would I have started it up? I want to USE it! Especially when I’m just checking some junk then shutting it back down again. This worked wonders and took no effort or confusion. THANKS!

  5. Thanks Hitori, I’m glad to hear it.

    I just realized another advantage of this technique: many third-party applications add little icons to the menubar. They’re very convenient, but most of them can’t be rearranged – unlike those provided by Apple. Therefore the order in which they launch is important, because any application with a long menu will hide the left-most icons. By specifying the launch order of these apps, you can ensure that the most important icons stay farther to the right, and get hidden by long menus less frequently.



Some HTML is OK

or, reply to this post via trackback.