Background
On older Macs, startup can take a long time. One of the main causes of this is apps that launch at startup. These apps can take the form of menu-bar apps like Dropbox and Growl, or full-fledged apps that you always use and have set to open at login.
Chances are, you don’t need to use all of those apps immediately after you log in. Today I’m going to share a way to use AppleScript to stagger the launch of these apps. That way, the apps you need first can start launching before the apps that you need later. Apps open faster when there is less ‘competition’ from others opening at the same time, so you’ll be able to use the apps you want first sooner after you log in.
On my older MacBook, the time from showing my desktop to loading all my startup items was shortened from 42 seconds to 35 seconds.
Preparation
To start with, let’s take a trip to System Preferences. Go to the Users and Groups pane and select your account on the left. Take a look at what you’ve got in the Login Items tab. Mine looks like this:
As you can see, I’ve got a lot of apps that are all going to try to launch all at once. This might be a good time to do a critical analysis of this list: are there any apps that you can remove outright? If so, great.
Let’s use some AppleScript to stagger out login a bit. Keep System Preferences open so that you can see your list, and open up AppleScript Editor.
The first step is to figure out what order you want your apps to launch in. I recommend making a list of your apps, putting them in order of priority, and deciding how long you’re willing to wait for them to launch. Once you’ve decided, let’s get scripting.
Writing the script
Our script will use two main commands: launch
and delay
. As you’ve guessed, launch
opens apps and delay
waits a specified amount of time. Here’s the basic syntax for opening an app called AppName:
tell application "AppName" to launch
And here’s the syntax for waiting a number of seconds:
delay 2
Using these two commands, you can construct your staggered login.
There are probably a few apps that you want to open right away when you log in. For me, these apps are Forklift and Dropbox. I’ll set the first lines of my script to open those apps:
tell application "Forklift" to launchNow, you have to think about how long you can wait until your next apps open. Generally, you should wait as long as it takes your first apps’ Dock icons to stop bouncing. If you can’t wait that long, wait as long as you feel you can. Once you’ve chosen a time, add a
tell application "Dropbox" to launch
delay
. It takes Dropbox and Forklift 2.5 seconds to launch, so I’ll add:
delay 2.5
Now, you basically repeat this pattern until you’ve launched all your apps. Decide what you want to open and how long you should wait to open the next round of apps.
Usage
Save your script as an app and put it in a safe, out-of-the way location (remember where it is; you’ll need to come back to it when you want to change your login items).
Go back to System Preferences. Remove all of the apps that you added to your script from the list, and add the app that you just saved:
Beware of apps that add themselves to System Preferences’ login items list. If you want an app to open at login, don’t use the app’s built in toggle for that; add it to your script instead.
Opening Files
Login items in System Preferences can be apps or files. Here’s how to open a file with your script:
tell application "Finder" to open file "Lion HD:Users:shortname:Desktop:file.txt"
Just replace the part in quotes with the path to your file (be sure to include the volume and use colons instead of slashes). You can use this in your script anywhere you would use a tell application...
line.
Resume
Lion makes things a little less straightforward because of Resume. If you have Resume enabled (‘Remember windows when logging back in’ checked), anything that was open when you logged out will open immediately when you log back in. This doesn’t break anything (the script will still run successfully), but the staggering won’t be respected. This leaves you with two options:
Disable Resume: If you disable Resume, everything will work as expected, i.e. your apps will launch as you’ve specified in your script. You won’t, though, have Resume’s functionality. That means that anything that was open when you logged out that isn’t in your script will not reopen automatically. Note that apps which support Resume will still load your previously opened windows when launched through your script.
Enable Resume: If you leave Resume enabled, any apps that were open when you logged out will be immediately reopened when you log back in. That means that anything in your script that was open when you logged out will open immediately, regardless of your staggering. You will, however, get the convenience of having apps that aren’t in your script reopen automatically.
Conclusion
I hope this tool helps you shave precious time of your Mac’s startup.
If you have any questions, feel free to ask in the comments and I’ll answer.
If you have any techincal questions or AppleScript questions, feel free to ask them on Ask Different.
To see more AppleScript-related blog posts, take a look at the AppleScript category.
Filed under AppleScript Automation
I had the exact same thing on our PowerMac G5. Good to know that other people are using AppleScript the way I am!
Are “launch” and “activate” synonymous?
I remember seeing most scripts do things like:
tell application “Safari” activate end tell
I’m assuming yours is more one-line friendly and doesn’t require the ‘end tell’?
The main difference between
launch
andactivate
is that launch doesn’t make the app active and bring it to the front. I like this for startup items, since it’s annoying when apps steal focus.The one-line aspect is made possible by the
to
. Any time you need totell
an application a one-line statement, you can usetell application "app" to ...
If you have a Lion-capable Mac, checkout Starupizer and Starupizer Lite which will do a very similar thing without AppleScript
http://itunes.apple.com/us/app/startupizer/id412397772?mt=12
http://itunes.apple.com/us/app/startupizer-lite/id435115679?mt=12
Hey, I didn’t know of that app. Very cool, and definitely a more user-friendly way to do this. Thanks for sharing.