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


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: 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 | # ]