Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Launch login items via AppleScript to avoid login delays System
I found that most of my startup items were things that I didn't need right away (Google Quick Search Box, LaunchBar, etc.). A simple AppleScript can be used to avoid the pileup of programs all trying to open at once at login. The result: a much faster login time.

The script works by opening programs one by one, with a little time in between. This gives the programs time to load, and allows you to use your computer as soon as you enter your password. The code looks like this:
tell application "Google Notifier" to activate
delay 3
tell application "LaunchBar" to activate
delay 3
set volume 4
tell application "BOINCManager" to activate
tell application "Quick Search Box" to activate
tell application "RealPlayer Downloader Agent" to activate
So, immediately opened is Google Notifier. Shortly thereafter comes LaunchBar. Afterwards, the volume is set to half loudness, and some other programs open.

To make this work for you, all you have to do is paste the above code into AppleScript Editor (in Applications » Utilities in 10.6) or Script Editor (in Applications » AppleScript in previous releases), replace the names of applications (tell application...) with yours, and change the delay times to suit your needs (the number represents seconds).

Finder windows can be triggerd by inserting the following code:
tell application "Finder" to open "Path:To:Folder"
Once you've completed the script, save it as an application. Set it as your one and only startup item. This will load at login, and launch the applications one by one.

The result is a computer that is ready to use immediately after login. It has also given me the freedom to use programs that I avoided before, because they caused a longer login time. The only disadvantage I've encountered: the AppleScript commands that are said to hide applications aren't working. As a result, programs pop up a window when they launch. For me, that's been a tiny price to pay for the speed.

[robg adds: This is a simpler version of a much older hint that worked around a then-bug in the OS. Because that original hint is ancient, and was referred to relative to the bug, I thought it worth publishing this new hint, and referring back to the original. The original hint also contains a way to force the launched programs to hide, via an entry in the Comments section of the Get Info window. If you're troubled by long login times while your startup items load, try one of these script-based workarounds.]
    •    
  • Currently 3.39 / 5
  You rated: 5 / 5 (28 votes cast)
 
[22,285 views]  

Launch login items via AppleScript to avoid login delays | 31 comments | Create New Account
Click here to return to the 'Launch login items via AppleScript to avoid login delays' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Launch login items via AppleScript to avoid login delays
Authored by: ascript_kiddie on Nov 18, '09 07:48:53AM

Hi. To avoid the apps opening windows, you might try telling the apps to launch rather than to activate. Can't confirm this completely because I don't have the apps in your script.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: fulmar2 on Nov 18, '09 08:06:44AM
This hint is good for another reason - on my Leopard Box, one of the login items is to mount a disk on the network. In tiger, you can just drag the disk into the login items, and it will mount every time you start the computer. Unfortunately, it Leopard, there appears to be a bug where the selected disk mount sometimes mounts, and sometimes doesn't. So, adding a little applescript to your login items, and then having the applescript try to mount this disk works every time. (I have mine try twice, just in case).

[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: post_break on Nov 18, '09 08:12:48AM

I do this but there is also a problem, some of these applications tend to steal focus so every 3 seconds (based on your script) your focus will change.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: V.K. on Nov 18, '09 08:33:07AM

good idea but change "activate" to "launch" everywhere in the script. this will launch those apps in the background. otherwise some of them will try to steal focus as poster post break indicated.

Edited on Nov 18, '09 08:34:19AM by V.K.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: psandiford on Nov 19, '09 07:25:46AM

The reason activate MAY be better is: some applications do not like "launch." Final Cut Pro, for example, will freeze and crash with "launch."



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Andrew J Freyer on Nov 18, '09 08:37:36AM
This is a great hint. Tried it right away, and I'll be damned if it doesn't work like a charm - can't believe I didn't think of this sooner! :)

Anyway, I changed the script a bit, to be more customizable. Set all apps in "theAppList" to the apps (in order) that you want to launch. "theDelay" is the delay.

Additionally, this will hide the application (flashing its window briefly - if someone can fix this that'd be great), and not cause ANY loss in focus.


set theAppList to {"Things", "Mail"} as list
set theDelay to 1

repeat with currentApp in theAppList
	tell application currentApp to launch
	delay theDelay
	tell application "Finder" to set visible of process currentApp to false
end repeat



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 18, '09 09:46:52AM
just a tweak on your script, using a list of records:
set theAppList to {{name:"Things", vis:false}, {name:"Mail", vis:true}}
set theDelay to 1

repeat with currentApp in theAppList
	tell application (name of currentApp) to launch
	delay theDelay
	tell application "Finder" to set visible of process (name of currentApp) to (vis of currentApp)
end repeat
this lets you set visibility on a case-by-case basis

[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Andrew J Freyer on Nov 18, '09 10:20:44AM

NICE!

I was looking for a way to do this, but I didn't think of nested lists for some reason...



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Andrew J Freyer on Nov 18, '09 10:28:16AM
Another slight edit:

repeat with currentApp in theAppList
	tell application (name of currentApp) to launch
	delay theDelay
	if (vis of currentApp) then
		tell application "Finder" to set visible of process (name of currentApp) to (vis of currentApp)
	end if
end repeat


[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: snit on Nov 18, '09 12:31:47PM

Curious why the delay is before setting visibility.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 18, '09 01:22:17PM

it may not be necessary, but sometimes apps need to be in a certain state before they will handle scripting correctly.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: everkleer80 on Nov 18, '09 01:35:41PM

I'm not sure if this 'certain state' means there needs to be some delay after the window opens, but if not then why not just wait (maybe loop with a delay of .1 or something) until a window is visible for the app and then hide the app (then delay some more if you want)... before Skype had fixed the bug where the hide option in login items wouldn't hide the buddy list, I wrote a script for it that hid the window the way I described. This way the window is only visible for up to .1 seconds instead of up to theDelay seconds.

For windowless apps you could just add a property haswindow:false.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Andrew J Freyer on Nov 18, '09 02:13:53PM

No, he's right. That's why I put the delay there.

Specifically for "Things" - when launched, if I try to hide it immediately, it is not yet prepared (fully opened) to accept the "hide" instruction.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 18, '09 01:40:59PM
refining it a bit more:
set theAppList to {{name:"Things", vis:false}, {name:"Mail", vis:true}}
set theDelay to 1

repeat with currentApp in theAppList
	tell application (name of currentApp) to launch
	delay theDelay
	tell application "System Events"
		try
			if background only of process (name of currentApp) is false then
				set visible of process (name of currentApp) to (vis of currentApp)
			end if
		end try
	end tell
end repeat


[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: thyvillageidiot on Nov 18, '09 03:51:16PM
Argh, this is such a good script, but I'm getting an error
Finder got an error: Can’t make visiblity of process "/Applications/iTunes.app/Contents/Resources/iTunesHelper.app" into type reference.

Furthermore, it is quite annoying to have the space switch and the window flash temporarily. Any work around yet?

[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 18, '09 05:04:51PM

read the comments - some of those issues are addressed.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: awado on Nov 18, '09 11:29:17AM
Here's what I use. I hope it fits your needs. It reads out aliases in a folder "Startitems" in your home folder and starts one after another and really wait till the app before has finished launching. You can define the order of launch by ordering it alphabetically. It displays a progress bar and closes (if desired) application windows, so you get a clean desktop when finished. I originally wrote it in german and did a quick translation now, hopefully without any typos.

-- AppStarter, 18.11.09, M.Kunzmann

-- Read aliases

try
	tell application "Finder" to set applist to original item of items of folder ((path to home folder) & "Startitems" as text)
on error
	display dialog name of me & ": " & return & return & "Folder 'Startitems' does not exist in home folder or invalid alias found!" with icon stop buttons {"OK"} default button 1
	return
end try

tell application "System Events" to keystroke "d" using {command down, option down}

-- Start progress bar

tell application "BP Progress Bar"
	launch
	tell progress indicator 1 of window 1 to set maximum value to count of applist
end tell


-- Starting apps

set progresscounter to 1

repeat with theapp in applist
	
	open theapp
	
	-- Find icon of app
	
	set pfad to POSIX path of (theapp as text)
	try
		set icondateiname to do shell script ("defaults read " & quoted form of pfad & "/Contents/Info" & " CFBundleIconFile")
		set icondatei to pfad & "/Contents/Resources/" & icondateiname
		if icondatei does not end with ".icns" then set icondatei to icondatei & ".icns"
	on error fehler
		set icondatei to "script"
	end try
	
	-- Adjust progress bar
	
	tell window 1 of application "BP Progress Bar"
		set content of text field 1 to "Please wait!"
		set content of text field 2 to "Starte '" & displayed name of theapp & "'…"
		set content of progress indicator 1 to progresscounter
		set image of image view 1 to load image icondatei
		show
		activate
	end tell
	
	-- Wait till launch is finished
	
	set appstarted to false
	repeat while not appstarted
		tell application "System Events"
			tell process (displayed name of theapp)
				set appstarted to (exists entire contents of first menu bar) or (exists entire contents of first UI element) or background only
			end tell
		end tell
	end repeat
	
	-- Close app windows (optional)
	
	try
		tell application (displayed name of theapp) to close every window
	end try
	set progresscounter to progresscounter + 1
end repeat


-- Minimize Finder windows

tell window 1 of application "BP Progress Bar" to set image of image view 1 to load image "script"
tell window 1 of application "BP Progress Bar" to set content of text field 2 to "Minimizing Finder windows…"
tell every window of application "Finder" to set collapsed to true

tell application "System Events" to keystroke "d" using {command down, option down}

tell application "BP Progress Bar" to quit
BP Progress Bar can be found there: http://scriptbuilders.net/files/bpprogressbar1.0.html
Edited on Nov 18, '09 11:31:03AM by awado


[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: awado on Nov 21, '09 03:22:08PM

I got a hint that my script doesn't work if suffixes are enabled. If you got any error message saying that an application name doesn't match, disable the suffix in the application name by checking "Hide suffix" in the get-info window or disable them all in the finder preferences.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: bcamp1973 on Nov 18, '09 11:36:46AM

what about helper applications or other scripts? do we need to provide a path to them? for example iTunesHelper, GrowlHelperApp, textexpanderd (for TextExpander) etc. How would that look?



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Agaethon on Nov 18, '09 10:01:16PM
Great scripts! I'm using the latest one from tedw and its working just great, except when i have it launch Quicksilver it will not hide it. Though it will work for Things. Whenever it launches I see the "flying" QS. When I had it set as a normal launch item before, as long as I set the checkmark to 'hide" it hid it. But now, even if I set the visibility to false it still shows it. I figure it has something to do with Quicksilver not fully loaded yet to except the visibility script. I tried increasing the delay and the order of the apps but no go. Any suggestions? Thanks!

set theAppList to {{name:"Things", vis:false}, {name:"Mail", vis:true}, {name:"Quicksilver", vis:false}}
set theDelay to 1

repeat with currentApp in theAppList
	tell application (name of currentApp) to launch
	delay theDelay
	tell application "System Events"
		try
			if background only of process (name of currentApp) is false then
				set visible of process (name of currentApp) to (vis of currentApp)
			end if
		end try
	end tell
end repeat
Edited on Nov 18, '09 10:02:45PM by Agaethon


[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 19, '09 12:29:36AM
Unfortunately, not every app is equally respectful of visibility requests. This might work a little better (replace the System Events tell block with this):
tell application "Finder"
	try
		open application (name of currentApp) with properties {visible:(vis of currentApp)}
	on error
		tell application "System Events"
			try
				if background only of process (name of currentApp) is false then
					set visible of process (name of currentApp) to (vis of currentApp)
				end if
			end try
		end tell
	end try
end tell


[ Reply to This | # ]
Been there, done it, but...
Authored by: TGV on Nov 19, '09 05:42:26AM
I had exactly the same idea two years ago or so, but I couldn't figure out how to get an AppleScript to delay. I tried the command sleep, which was a mistake. Ultimately, I had everything opened through a shell script (with open -a), but this is of course the neat solution we all like to see. Thanks!

[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: systemsboy on Nov 19, '09 07:48:34AM

Wow. Superb hint. It really does speed up login. Seems like Apple should build this sort of thing right into the Login Items behavior.

Until they do, I'll be using this method.

Thanks!

-systemsboy



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: kimballk on Nov 20, '09 05:17:49AM

The script makes the code necessary to activate an application quite clear. But please explain to non-scripter how to activate items on startup which are not the Applications folder. For example:
Path = "/Applications/Utilities/0-SYSTEM UPKEEP & MONITOR/00-BASIC/SMARTReporter.app";
Path = "/Users/00/Library/Application Support/Awaken/AwakenHelper.app";
Path = "/Users/00/Library/PreferencePanes/Default Folder X.prefPane/Contents/Resources/Default Folder X Helper.app";
Path = "/Users/00/Library/Application Support/A Better Finder Suite/ABF HotKey.app";
Path = "/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app";

---
Kimball Kramer



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 20, '09 08:27:15AM
All you need to know to use this script on any application is the name that the system uses to call it. to get that, open Script Editor and use the line: tell application "System Events" to get name of every process. This line will print out a list of all the names of every process running from your user account. You can look through it to find the name of whatever process you're interested in (the one you want is generally pretty obvious), and then copy that into the script.

[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: kimballk on Nov 20, '09 10:55:06AM

Thank you.

---
Kimball Kramer



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Jonsi on Nov 20, '09 05:23:12AM

What about bcamp1973's question above about... "helper applications or other scripts? do we need to provide a path to them? for example iTunesHelper, GrowlHelperApp, textexpanderd (for TextExpander) etc."

Also, isn't it possible to let the script read a textfile with the names of the applications and their "vis"-status?
E.g.:
Things, false
Mail, true
… etc.
Unfortunately I'm no Applescript-guru :-(



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: aGr[j5(6WU on Dec 02, '09 08:38:06AM
There seems to be at least two ways to launch helpers, etc. The first is to use the app's Application ID, which in the case of GrowlHelper looks like this: com.Growl.GrowlHelperApp
See here for further examples and info. I found GrowlHelperApp's Application ID by looking in my user's /Library/Preferences folder. Unfortunately, EyeTV Helper doesn't seem to have a .plist, so instead I had to use the "do shell script" command. So, this is the relevant part of my new LoginItem script:
tell application id "com.Growl.GrowlHelperApp" to launch
delay 10
do shell script "open /Applications/EyeTV.app/Contents/Resources/'EyeTV Helper.app'"
Works fine here. Hope this helps someone else. If anyone finds the Application ID for EyeTV Helper please post it here.

[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: David Allen on Dec 19, '09 02:52:05PM
I just placed "EyeTV Helper" in the script and it opens it just fine. Since many of the things that open at startup/login on my kit are right side menu bar items, I have left off the visibility part of the script for those items. Since this was first published back in NOV I have used the most refined version on three Macs and it works great on all of them. It is really nice not needing to sit and wait to get control of my Mac back!
---
Dah•veed |David Allen|
Monterrey, NL, Mexico
Edited on Dec 19, '09 02:56:04PM by David Allen


[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: brownlaronn on Jan 10, '11 08:31:24AM

Thanks for the script it works like a charm.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Maxikubik on Mar 24, '11 06:32:43AM

I tried this and it took about 3 minutes from the login until it was done using this hint, and "only" 2.5 minutes by using the startup items in the accounts pref pane. So it didn't work out very well for me.



[ Reply to This | # ]