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

An AppleScript workaround for login items bug System
There are some reported instances, as well as an Apple KnowledgeBase article, concerning OS X hanging when multiple login items are specified. David Nelson, the author of the "Is Classic running?" AppleScript mentioned here recently has written a script which addresses this issue.

David explains it much better than I could, so here's what he said about the script:
This script is a workaround for the issue of applications hanging or causing the system to hang when multiple applications are specified as login items in System Preferences > Login panel.

The workaround is accomplished by specifying the script as the sole login item. When the script runs it opens any aliases it finds in a "Login Items" folder of its own, which resides in the same folder as the script. The script waits five seconds between opening each alias, which avoids the bug that is causing problems when multiple apps are launched at once. If you want an application to be hidden after it is launched, simply do a Get Info on its alias in the script's "Login Items" folder and enter the word "hide" in the comment field.
A simple, effective solution to the problem, at least until its officially addressed by Apple.

Read the rest of the article for David's script...

property pPathToLoginItemsFolder : "" -- The script will set this value.
set loginItemsList to {} -- The script will set this value.
set interLaunchDelay to 5 -- Seconds between launching applications. Feel free to fiddle with this one.

tell application "Finder"
set pPathToLoginItemsFolder to ((container of (path to me) as alias) as text) & "Login Items:"
set loginItemsList to every item of folder pPathToLoginItemsFolder whose kind is "Alias"
repeat with i in loginItemsList
open i
delay interLaunchDelay
if (comment of i is "hide") then
set visible of process ((displayed name of i) as text) to false
end if
end repeat
end tell
As explained above, just save the script into a folder, create a new Login Items folder in that same folder, and then place aliases to your startup apps in the Login Items folder. Add the script as the only app to be run at login, and you should have a viable multiple login items launch solution.
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[17,192 views]  

An AppleScript workaround for login items bug | 13 comments | Create New Account
Click here to return to the 'An AppleScript workaround for login items bug' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Re: Login script
Authored by: chrispar on Dec 10, '01 07:52:02AM

Great script! But, how do I make an alias of iTunesHelper when I can't find it?



[ Reply to This | # ]
Re: Login script
Authored by: Yertman on Dec 10, '01 05:35:24PM

Hello,

The iTunesHelper app is located inside of the iTunes.app package, right here to be specific: iTunes.app/Contents/Resources/iTunesHelper.app To access the contents of a package, right click on the package and select "View package contents" from the contextual menu.

Unfortunately, it is not quite a normal application as it does not open if you double click on it.

You can however make iTunesHelper launch with AppleScript:

tell application "iTunesHelper"
activate
end tell

My login items script only opens alias files, so if you save this script directly in the login items folder it will be ignored. Instead save the scipt someplace else then make an alias to it and put that in the login items folder. Another option would be to paste this little scrap of script right into the login items script.


HTH
David Nelson (AKA Yertman)



[ Reply to This | # ]
Re: Login script
Authored by: chrispar on Dec 12, '01 05:12:42AM

Thanks - that worked!



[ Reply to This | # ]
Great Script - even sped up login
Authored by: saint.duo on Dec 10, '01 10:57:30AM

This script has solved one of my biggest issues on my beige G3. Typically, if I have 3 or more items in my login items, there is a 70% chance that the computer will hang on login. Well, having added Microsoft Office last night, that made three (MagicMenu, MouseWorks Background, and the Microsoft Database Daemon).

The hard disk activity when I login has dropped tremendously after using this script instead of putting those things in my login items, and the time has dropped, as well.

One thing to note, is that the Microsoft Database Daemon put itself back into the login items upon logout/login. If anyone knows how to keep it from doing this, I would love to know.



[ Reply to This | # ]
Can't get App to hide
Authored by: evlded on Dec 11, '01 04:24:27PM

I created the script and all works well, except I have netbarrier for x and I have typed hide and "hide" in the comments window on the alias and it will not hide it...so if anyone can help please reply...thanks...excellent script though!



[ Reply to This | # ]
Can't get App to hide
Authored by: Yertman on Dec 11, '01 06:06:00PM

Hi,

Just the word hide, without quotes, in the comments field should do it.

You could also try changing the script so the line that reads:
if (comment of i is "hide") then

To:
if (comment of i contains "hide") then

Also try putting the word hide in some of the other alias file's comment boxes, and see if the script hides them.

HTH
David Nelson





[ Reply to This | # ]
Some improvements
Authored by: nstanger on Dec 13, '01 11:40:34PM
I like this script, but after playing around with it for a little while I found a couple of things that could do with improving. First, the standard Login Items launches everything in the background, which looks much nicer (well, to me anyway). Second, if you rename the aliases (e.g., to set the launching order), process hiding no longer works because the script uses the alias name rather than the name of the original item. Actually, it's also just occured to me that the second one would also prevent you from "hiding" documents. (hack, hack :) Here's an updated version of the script that fixes these:
property pPathToLoginItemsFolder : "" -- The script will set this value.
set loginItemsList to {} -- The script will set this value.
set interLaunchDelay to 5 -- Seconds between launching applications. Feel free to fiddle with this one.
tell application "Finder"
set pPathToLoginItemsFolder to ((container of (path to me) as alias) as text) & "Login Items:"
set loginItemsList to every alias file of folder pPathToLoginItemsFolder
repeat with i in loginItemsList
delay interLaunchDelay

-- Getting the original item of the alias allows us to have aliases with different names from
-- the original items. If we don't do this, it screws up hiding processes below because the
-- process name doesn't match the item name.
set originalItem to original item of i

-- It looks nicer if applications open in the background without coming to the front.
-- Using "open" won't do this, but "launch application" will. However, we can't just use
-- "launch application" for everything because that doesn't let us include documents
-- in the login items. We therefore need to check first whether we're dealing with an
-- application file.
if (class of originalItem is application file) then
-- Odd: "launch application" doesn't work without the "tell me", don't know why.
-- We convert originalItem to a string to get the full path to the application (see
-- http://www.applescriptsourcebook.com/tips/launchbycreator.html for an
-- explanation).
tell me to launch application (originalItem as string)

-- Hide those processes that should be.
if (comment of i is "hide") then
set visible of process ((displayed name of originalItem) as text) to false
end if
else -- Not an application, so just open it.
open originalItem

-- Hide those processes that should be.
if (comment of i is "hide") then
set appName to (displayed name of application file id (creator type of originalItem)) as text
set visible of process appName to false
end if
end if
end repeat
end tell
I haven't tested it extensively, but it appears to do the job. Hope you find it useful!

[ Reply to This | # ]
Some improvements
Authored by: thatch on Dec 19, '01 03:15:32AM

I had some problems with another applescript login item as well as some problems with other user accounts with this tip.

An applescript I had made for moving my browser cache to the trash on login stayed open and became unresponsive when it was a run only script so I had to put it into the regular login items together with this tip script.

When I tried to use this setup in other user accounts, it wouldn't run because of a certain login item called Cookie Dog Login which is kept in ~/Library/Preferences and is listed as a document not an application. It is also in reality a carbon app. The reason it doesn't work is because it doesn't have the correct permissions being another user account.

But I do like the way this tip works for my admin account. I set the time variable to only one second and it works just fine. It's certainly better than having all the login items launch at once. And you can still control the order they launch too.



[ Reply to This | # ]
Some improvements
Authored by: charlau on Mar 13, '10 08:29:25AM
Your script's great, thanks! I started with it, adding growl notifications. so here it is: (Took out the comments to not be repetitive here. I also took out the delay. One thing I'm not sure about is how to get the path for the grolwhelper - here it's hardcoded).
property pPathToLoginItemsFolder : "" -- The script will set this value.
set loginItemsList to {} -- The script will set this value.

setupGrowl()

tell application "Finder"
	set pPathToLoginItemsFolder to ((container of (path to me) as alias) as text) & "Login Items:"
	set loginItemsList to every alias file of folder pPathToLoginItemsFolder
end tell

repeat with i in loginItemsList
	
	tell application "Finder"

		set originalItem to original item of i
		
		if (class of originalItem is application file) then
			tell me to launch application (originalItem as string)
			
			if (comment of i is "hide") then
				set visible of process ((displayed name of originalItem) as text) to false
			end if
		else
			open originalItem
			
			if (comment of i is "hide") then
				set appName to  
				(displayed name of application file id (creator type of originalItem)) as text

				set visible of process appName to false
			end if
		end if
	end tell
	
	set justAppName to getAppName(originalItem as string)
	
	tell application "GrowlHelperApp"
		notify with name 
			"Program started" title 
			"The following program launched" description justAppName 
			application name 
			"Custom login items" icon of application justAppName
	end tell
	
end repeat


on setupGrowl()
	
	tell application "System Events"
		set isRunning to 
			(count of (every process whose name is "GrowlHelperApp")) > 0
	end tell
	
	if (isRunning = 0) then
		open application  
"Macintosh HD:Library:PreferencePanes:Growl.prefPane:Contents:Resources:GrowlHelperApp.app"
		delay 2
	end if
	
	
	tell application "GrowlHelperApp"

		set the allNotificationsList to {"Program started"}
		
		set the enabledNotificationsList to {"Program started"}
		
		register as application 
			"Custom login items" all notifications allNotificationsList 
			default notifications enabledNotificationsList 
			icon of application "Script Editor"
		
	end tell
	
end setupGrowl

on getAppName(thePath)
	
	set oldDelims to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to {":"}
		set withExt to the last text item in (thePath as string) as string
		set AppleScript's text item delimiters to {"."}
		set withoutExt to the first text item in withExt as string
		set AppleScript's text item delimiters to oldDelims
		return withoutExt
	on error
		set AppleScript's text item delimiters to oldDelims
	end try
	
end getAppName



[ Reply to This | # ]
Starting other apps
Authored by: cz on Jan 04, '02 12:35:37AM

I have an emech that I'd like to start at boot/login. How can I get this script to launch it and similar programs?

Thanks



[ Reply to This | # ]
An AppleScript workaround for login items bug
Authored by: seasprite on Mar 27, '07 04:11:42PM

I'm trying to solve a vexing problem prerquisite to using your applescript. I cannot for some reason remove items from my Login Items List. I am an admin and all of that. I click on the - and nothing happens. I have searched the hard drive looking for anything that would appear to store this information and have found nothing so far. Any idea where apple hides this info?

Thanks in advance



[ Reply to This | # ]
An AppleScript workaround for login items bug
Authored by: tedw on Mar 13, '10 10:29:11PM
They are all listed in the file ~/Library/Preferences/com.apple.loginitems.plist. Deleting or editing this file should solve any immediate problems with stuck login item.

[ Reply to This | # ]
a Ruby version that dynamically gets the list of Login Items to launch
Authored by: HotFusionMan on Oct 20, '10 09:34:49PM

I really wanted the script to automatically know what my Login Items are instead of manually making aliases in a folder for it. Based on this previous comment I was able to bang out a Ruby version (much quicker for me than modifying the AppleScript code). It retains the Growl setup but omits the capability of launching the Login Items in the background (so I could actually finish the script tonight rather than next week ;) ).

Save the following code to a file and chmod +x that file in Terminal.app (or whatever shell you prefer) so it can be executed. I haven't gone all the way through to testing making it the sole Login Item the way one would ultimately want to, but I did confirm it works with the stock /usr/bin/ruby without needing any 3rd-party libraries (at least on Snow Leopard, but I believe any version of Ruby >= 1.8 should also work, because that's when REXML was included into the Ruby standard library).

Caveat emptor.

#!/usr/bin/env ruby

require 'rexml/document'

def set_up_Growl
  if `ps -ax | grep GrowlHelperApp\.app | grep -v grep` == '' then
    system( 'open /Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app' )
  end
end

set_up_Growl

loginitems_plist_xml = `plutil -convert xml1 -o - -- ~/Library/Preferences/com.apple.loginitems.plist`

REXML::Document.new( loginitems_plist_xml ).each_element( '/plist/dict/dict/array/dict/dict/dict' ) { |login_item_dict|
  index_of_Path_key = i = 0 ; elements = []
  login_item_dict.each_element { |e|
    elements << e

    if e.text == 'Path' then
      index_of_Path_key = i
    end

    i += 1
  }

  login_item = elements[index_of_Path_key + 1].text
  system( "open '#{login_item}'" )
  sleep( 1 )
}
</pre>

     

[ Reply to This | # ]