<

Script to Delay and Stagger the Launch of Login Items Under OS X

Published on
10,326 Points
4,326 Views
Last Modified:
Approved
If you are using Mac OS X and have a large number of login items set up in accounts, under system preferences, you may find that your computer is sluggish and unresponsive during startup until everything is done launching.

Another problem that arises from time to time is that a login item fails because it requires a resource that is not ready.

The attached script enables you to defer and stagger any or all of your startup items, to alleviate these issues.

Note: It works with a mechanism similar to the OS 9 (and earlier) startup items folder.


How to use the script:
1. make a new folder named "staggeredlaunchitems" in your preferences folder (the one in the library in your home directory).

2. put aliases of the files you want to open or applications you want to launch into the staggeredlaunchitems folder.

3. launch AppleScript editor and paste the attached code snippet into a new AppleScript:
-- this script emulates the OS 9 (and earlier) startup items folder, with the added ability to stagger and delay launches
-- to use this script, 
--   1. make a new folder in your preference folder (the one in the library in your home directory) called (exactly)
--       staggeredlaunchitems
--   2. put aliases of the files you want to open/applications you want to launch into the staggeredlaunchitems
--   3. customize the delays, if desired, in the two "set" commands at the top of the script
--   4. save this script as an application, and make it a login item in (in accounts under system prefs)

set launchdelay to 10 -- change this as required to customize the number of seconds before the first item launches
set itemdelay to 5 -- change this as required to customize the number of seconds between launches

tell application "Finder"
	set launchitemsfolder to (path to preferences folder as string) & "staggeredlaunchitems"
	delay launchdelay
	repeat with x from 1 to (the number of files of folder launchitemsfolder)
		set thefile to (file x of folder launchitemsfolder) as string
		do shell script "open " & (quoted form of POSIX path of thefile)
		delay itemdelay
	end repeat
end tell
quit

Open in new window


4. customize the delays, if desired, in the two "set" commands at the top of the script.
launchdelay -- the number of seconds before the first item launches.
itemdelay -- the number of seconds between each item's launch.

5. save the above script as an application, and make it a login item in accounts, under system preferences.

6. any login items that are now being launched by the script should be removed from the login items pane in accounts, under system preferences.


The files in your staggeredlaunchitems folder will now launch in accordance with the set delays. They will launch in alphabetical order according to the names of the aliases. Change the names of the aliases to change the launch order.

0
Author:nxnw
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free